From 81f10b0c5ba421a74fd228d7c48fc685e058c457 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sun, 31 May 2020 12:34:02 +0200 Subject: [PATCH] [core] Synchronize notifyConnectionError() Synchronize notifyConnectionError() so that only one exception is handled and remove the ASYNC_BUT_ORDERED usage here. The ASYNC_BUT_ORDERED was added with 7d2c3ac9f ("Do not call synchronized methods in reader/writer thread"), but is no longer necessary, since the Semaphores where replaced with conditions in the previous commit. --- .../smack/AbstractXMPPConnection.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java index 2d0f7c693..0da542111 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java @@ -963,6 +963,8 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { callConnectionClosedListener(); } + private final Object notifyConnectionErrorMonitor = new Object(); + /** * Sends out a notification that there was an error with the connection * and closes the connection. @@ -970,14 +972,13 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { * @param exception the exception that causes the connection close event. */ protected final void notifyConnectionError(final Exception exception) { - if (!isConnected()) { - LOGGER.log(Level.INFO, "Connection was already disconnected when attempting to handle " + exception, - exception); - return; - } + synchronized (notifyConnectionErrorMonitor) { + if (!isConnected()) { + LOGGER.log(Level.INFO, "Connection was already disconnected when attempting to handle " + exception, + exception); + return; + } - // TODO: Remove this async but ordered? - ASYNC_BUT_ORDERED.performAsyncButOrdered(this, () -> { // Note that we first have to set the current connection exception and notify waiting threads, as one of them // could hold the instance lock, which we also need later when calling instantShutdown(). setCurrentConnectionExceptionAndNotify(exception); @@ -995,7 +996,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { // Notify connection listeners of the error. callConnectionClosedOnErrorListener(exception); }, AbstractXMPPConnection.this + " callConnectionClosedOnErrorListener()"); - }); + } } /**