1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 06:12:05 +01:00

Call shutdown() in connect() on exception

to clean up the state build up by connect().

Related to SMACK-855 there is the possiblitiy of a stray (writer)
thread if, for example, tlsHandled.checkifSuccessOrWaitorThrow() in
XMPPTCPConnection.connectInternal() throws. This commit should prevent
that.
This commit is contained in:
Florian Schmaus 2019-03-04 17:08:53 +01:00
parent f4ebd530e6
commit f602de8771
4 changed files with 29 additions and 11 deletions

View file

@ -263,6 +263,11 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
client = null; client = null;
} }
instantShutdown();
}
@Override
public void instantShutdown() {
setWasAuthenticated(); setWasAuthenticated();
sessionID = null; sessionID = null;
done = true; done = true;

View file

@ -405,15 +405,19 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
tlsHandled.init(); tlsHandled.init();
streamId = null; streamId = null;
// Perform the actual connection to the XMPP service try {
connectInternal(); // Perform the actual connection to the XMPP service
connectInternal();
// If TLS is required but the server doesn't offer it, disconnect // If TLS is required but the server doesn't offer it, disconnect
// from the server and throw an error. First check if we've already negotiated TLS // from the server and throw an error. First check if we've already negotiated TLS
// and are secure, however (features get parsed a second time after TLS is established). // and are secure, however (features get parsed a second time after TLS is established).
if (!isSecureConnection() && getConfiguration().getSecurityMode() == SecurityMode.required) { if (!isSecureConnection() && getConfiguration().getSecurityMode() == SecurityMode.required) {
shutdown(); throw new SecurityRequiredByClientException();
throw new SecurityRequiredByClientException(); }
} catch (SmackException | IOException | XMPPException | InterruptedException e) {
instantShutdown();
throw e;
} }
// Make note of the fact that we're now connected. // Make note of the fact that we're now connected.
@ -763,6 +767,11 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
*/ */
protected abstract void shutdown(); protected abstract void shutdown();
/**
* Performs an unclean disconnect and shutdown of the connection. Does not send a closing stream stanza.
*/
public abstract void instantShutdown();
@Override @Override
public void addConnectionListener(ConnectionListener connectionListener) { public void addConnectionListener(ConnectionListener connectionListener) {
if (connectionListener == null) { if (connectionListener == null) {

View file

@ -100,6 +100,11 @@ public class DummyConnection extends AbstractXMPPConnection {
callConnectionClosedListener(); callConnectionClosedListener();
} }
@Override
public void instantShutdown() {
shutdown();
}
@Override @Override
public boolean isSecureConnection() { public boolean isSecureConnection() {
return false; return false;
@ -226,4 +231,5 @@ public class DummyConnection extends AbstractXMPPConnection {
} }
} }
} }
} }

View file

@ -478,9 +478,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
shutdown(false); shutdown(false);
} }
/** @Override
* Performs an unclean disconnect and shutdown of the connection. Does not send a closing stream stanza.
*/
public synchronized void instantShutdown() { public synchronized void instantShutdown() {
shutdown(true); shutdown(true);
} }