From 66acb921c44786b5de7b4843bbe5e466ea13e78d Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Fri, 13 Feb 2026 20:15:25 -0800 Subject: [PATCH] fix(disconnect): try to solve race condition --- .../kotlin/org/connectbot/sshlib/client/SshConnection.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sshlib/src/main/kotlin/org/connectbot/sshlib/client/SshConnection.kt b/sshlib/src/main/kotlin/org/connectbot/sshlib/client/SshConnection.kt index 86297a3..a7ee905 100644 --- a/sshlib/src/main/kotlin/org/connectbot/sshlib/client/SshConnection.kt +++ b/sshlib/src/main/kotlin/org/connectbot/sshlib/client/SshConnection.kt @@ -2048,6 +2048,7 @@ class SshConnection( private fun startPacketLoop() { if (packetLoopJob != null) return packetLoopJob = connectionScope.launch { + var loopException: Exception? = null try { while (isActive) { processNextPacket() @@ -2061,7 +2062,7 @@ class SshConnection( } else { logger.warn("Packet loop ended unexpectedly", e) } - _disconnectedFlow.tryEmit(e) + loopException = e } finally { for (ch in channels.values) { ch.onClose() @@ -2069,6 +2070,9 @@ class SshConnection( for (ch in forwardingChannels.values) { ch.onClose() } + if (loopException != null) { + _disconnectedFlow.tryEmit(loopException) + } } } }