mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-24 23:32:05 +01:00
[tcp] Ignore exceptions in reader thread if writer was terminated
If we do not ignore the exception, then users may receive an exception via connectionClosedOnError() on connection termination. Those exceptions are typically unwanted if they are caused e.g. because the server does not send a closing stream tag. We previously ignored exceptions in this case already, but that behavior was changed with [1:57961a8cc1
]. This commit re-adds the behavior. 1:57961a8cc1
Remove SynchronizationPoint
This commit is contained in:
parent
4adbd21a0f
commit
f9114f780d
1 changed files with 19 additions and 9 deletions
|
@ -1141,16 +1141,26 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
// The exception can be ignored if the the connection is 'done'
|
|
||||||
// or if the it was caused because the socket got closed.
|
|
||||||
if (!done) {
|
|
||||||
// Set running to false since this thread will exit here and notifyConnectionError() will wait until
|
// Set running to false since this thread will exit here and notifyConnectionError() will wait until
|
||||||
// the reader and writer thread's 'running' value is false.
|
// the reader and writer thread's 'running' value is false.
|
||||||
running = false;
|
running = false;
|
||||||
// Close the connection and notify connection listeners of the
|
|
||||||
// error.
|
String ignoreReasonThread = null;
|
||||||
notifyConnectionError(e);
|
|
||||||
|
boolean writerThreadWasShutDown = packetWriter.queue.isShutdown();
|
||||||
|
if (writerThreadWasShutDown) {
|
||||||
|
ignoreReasonThread = "writer";
|
||||||
|
} else if (done) {
|
||||||
|
ignoreReasonThread = "reader";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ignoreReasonThread != null) {
|
||||||
|
LOGGER.log(Level.FINER, "Ignoring " + e + " as " + ignoreReasonThread + " was already shut down");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close the connection and notify connection listeners of the error.
|
||||||
|
notifyConnectionError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue