Skip to content

Commit

Permalink
Throw exception if using blocking mailer from IO thread
Browse files Browse the repository at this point in the history
This prevents a potential deadlock.

Fixes #3223
  • Loading branch information
stuartwdouglas committed Mar 19, 2020
1 parent a0fd85a commit fd98d59
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();
}
}

0 comments on commit fd98d59

Please sign in to comment.