1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-24 21: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;
}
instantShutdown();
}
@Override
public void instantShutdown() {
setWasAuthenticated();
sessionID = null;
done = true;

View file

@ -405,6 +405,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
tlsHandled.init();
streamId = null;
try {
// Perform the actual connection to the XMPP service
connectInternal();
@ -412,9 +413,12 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
// 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).
if (!isSecureConnection() && getConfiguration().getSecurityMode() == SecurityMode.required) {
shutdown();
throw new SecurityRequiredByClientException();
}
} catch (SmackException | IOException | XMPPException | InterruptedException e) {
instantShutdown();
throw e;
}
// Make note of the fact that we're now connected.
connected = true;
@ -763,6 +767,11 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
*/
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
public void addConnectionListener(ConnectionListener connectionListener) {
if (connectionListener == null) {

View file

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

View file

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