From cd64c4a578669cd1dd307c41f1808ec2a3adf27a Mon Sep 17 00:00:00 2001 From: Clement Escoffier Date: Thu, 15 Sep 2022 08:29:09 +0200 Subject: [PATCH] Fix error reporting when during an authentication chain, the connection is closed by the remote server --- .../vertx/ext/mail/impl/SMTPConnection.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/vertx/ext/mail/impl/SMTPConnection.java b/src/main/java/io/vertx/ext/mail/impl/SMTPConnection.java index 0d08ab91..203ccae9 100644 --- a/src/main/java/io/vertx/ext/mail/impl/SMTPConnection.java +++ b/src/main/java/io/vertx/ext/mail/impl/SMTPConnection.java @@ -116,13 +116,18 @@ void init(Handler initialReplyHandler) { void handleNSException(Throwable t) { if (!socketClosed && !shutdown) { + // shutdown() clear the handler, so gets a reference on the error handler first. + Handler handler; + synchronized (this) { + handler = errorHandler; + } shutdown(); // some SMTP servers may not close the TCP connection gracefully // https://github.com/vert-x3/vertx-mail-client/issues/175 if (quitSent) { log.debug("got an exception on the netsocket after quit sent", t); } else { - handleError(t); + handleError(t, handler); } } else { log.debug("not returning follow-up exception", t); @@ -294,6 +299,20 @@ private void handleError(Throwable t) { }); } + private void handleError(Throwable t, Handler handler) { + context.emit(t, err -> { + if (handler != null) { + handler.handle(err); + } else { + if (log.isDebugEnabled()) { + log.error(t.getMessage(), t); + } else { + log.error(t.getMessage()); + } + } + }); + } + boolean isSsl() { return ns.isSsl(); }