From fd98d59afbe353791b32bf4cbcec07e59c070c5d Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Thu, 19 Mar 2020 11:56:03 +1100 Subject: [PATCH] Throw exception if using blocking mailer from IO thread This prevents a potential deadlock. Fixes #3223 --- .../java/io/quarkus/mailer/runtime/BlockingMailerImpl.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/extensions/mailer/runtime/src/main/java/io/quarkus/mailer/runtime/BlockingMailerImpl.java b/extensions/mailer/runtime/src/main/java/io/quarkus/mailer/runtime/BlockingMailerImpl.java index 35957de7c8b16..89db004415314 100644 --- a/extensions/mailer/runtime/src/main/java/io/quarkus/mailer/runtime/BlockingMailerImpl.java +++ b/extensions/mailer/runtime/src/main/java/io/quarkus/mailer/runtime/BlockingMailerImpl.java @@ -6,6 +6,7 @@ import io.quarkus.mailer.Mail; import io.quarkus.mailer.Mailer; import io.quarkus.mailer.ReactiveMailer; +import io.quarkus.runtime.BlockingOperationControl; /** * Implementation of {@link Mailer} relying on the {@link ReactiveMailer} and waiting for completion. @@ -18,6 +19,10 @@ public class BlockingMailerImpl implements Mailer { @Override public void send(Mail... mails) { + if (!BlockingOperationControl.isBlockingAllowed()) { + throw new RuntimeException( + "Attempted a blocking operation from the IO thread. If you want to send mail from an IO thread please use ReactiveMailer instead, or dispatch to a worker thread to use the blocking mailer."); + } mailer.send(mails).toCompletableFuture().join(); } }