Skip to content

Commit 66acb92

Browse files
committed
fix(disconnect): try to solve race condition
1 parent 3026dac commit 66acb92

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

sshlib/src/main/kotlin/org/connectbot/sshlib/client/SshConnection.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2048,6 +2048,7 @@ class SshConnection(
20482048
private fun startPacketLoop() {
20492049
if (packetLoopJob != null) return
20502050
packetLoopJob = connectionScope.launch {
2051+
var loopException: Exception? = null
20512052
try {
20522053
while (isActive) {
20532054
processNextPacket()
@@ -2061,14 +2062,17 @@ class SshConnection(
20612062
} else {
20622063
logger.warn("Packet loop ended unexpectedly", e)
20632064
}
2064-
_disconnectedFlow.tryEmit(e)
2065+
loopException = e
20652066
} finally {
20662067
for (ch in channels.values) {
20672068
ch.onClose()
20682069
}
20692070
for (ch in forwardingChannels.values) {
20702071
ch.onClose()
20712072
}
2073+
if (loopException != null) {
2074+
_disconnectedFlow.tryEmit(loopException)
2075+
}
20722076
}
20732077
}
20742078
}

0 commit comments

Comments
 (0)