From a2c67a6e383226253dcc5749a6b8aaf10bd997a7 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 12 Mar 2024 19:01:39 +0100 Subject: [PATCH] ensure that jingle ft transport is terminated --- .../jingle/JingleFileTransferConnection.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleFileTransferConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleFileTransferConnection.java index 845f91ecc..749a44e10 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleFileTransferConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleFileTransferConnection.java @@ -253,6 +253,7 @@ public class JingleFileTransferConnection extends AbstractJingleConnection id.account.getJid().asBareJid() + ": improperly formatted contents", Throwables.getRootCause(e)); respondOk(jinglePacket); + terminateTransport(); sendSessionTerminate(Reason.of(e), e.getMessage()); return; } @@ -534,6 +535,7 @@ public class JingleFileTransferConnection extends AbstractJingleConnection if (isTerminated()) { return; } + terminateTransport(); final Throwable rootCause = Throwables.getRootCause(throwable); Log.d(Config.LOGTAG, "unable to send session accept", rootCause); sendSessionTerminate(Reason.ofThrowable(rootCause), rootCause.getMessage()); @@ -603,6 +605,7 @@ public class JingleFileTransferConnection extends AbstractJingleConnection id.account.getJid().asBareJid() + ": improperly formatted contents", Throwables.getRootCause(e)); respondOk(jinglePacket); + terminateTransport(); sendSessionTerminate(Reason.of(e), e.getMessage()); return; } @@ -646,6 +649,7 @@ public class JingleFileTransferConnection extends AbstractJingleConnection id.account.getJid().asBareJid() + ": improperly formatted contents", Throwables.getRootCause(e)); respondOk(jinglePacket); + terminateTransport(); sendSessionTerminate(Reason.of(e), e.getMessage()); return; } @@ -708,6 +712,7 @@ public class JingleFileTransferConnection extends AbstractJingleConnection } else if (transportInfo instanceof SocksByteStreamsTransportInfo.CandidateUsed candidateUsed) { if (!socksBytestreamsTransport.setCandidateUsed(candidateUsed.cid)) { + terminateTransport(); sendSessionTerminate( Reason.FAILED_TRANSPORT, String.format( @@ -734,6 +739,7 @@ public class JingleFileTransferConnection extends AbstractJingleConnection id.account.getJid().asBareJid() + ": improperly formatted contents", Throwables.getRootCause(e)); respondOk(jinglePacket); + terminateTransport(); sendSessionTerminate(Reason.of(e), e.getMessage()); return; } @@ -843,8 +849,9 @@ public class JingleFileTransferConnection extends AbstractJingleConnection if (transport == null) { return; } - // TODO consider setting transport callback to null. requires transport to handle null callback - //transport.setTransportCallback(null); + // TODO consider setting transport callback to null. requires transport to handle null + // callback + // transport.setTransportCallback(null); transport.terminate(); this.transport = null; } @@ -875,8 +882,12 @@ public class JingleFileTransferConnection extends AbstractJingleConnection } @Override - public void onFailure(@NonNull Throwable throwable) { - onFileTransmissionFailed(throwable); + public void onFailure(@NonNull final Throwable throwable) { + // The state transition in here should be synchronized to not race with the + // state transition in receiveSessionTerminate + synchronized (JingleFileTransferConnection.this) { + onFileTransmissionFailed(throwable); + } } }, MoreExecutors.directExecutor());