fix(android): stabilize BridgeSession shutdown

This commit is contained in:
Peter Steinberger
2025-12-30 04:42:02 +01:00
parent d2ac672f47
commit c0c6782a17

View File

@@ -77,6 +77,8 @@ class BridgeSession(
fun disconnect() { fun disconnect() {
desired = null desired = null
// Unblock connectOnce() read loop. Coroutine cancellation alone won't interrupt BufferedReader.readLine().
currentConnection?.closeQuietly()
scope.launch(Dispatchers.IO) { scope.launch(Dispatchers.IO) {
job?.cancelAndJoin() job?.cancelAndJoin()
job = null job = null
@@ -218,10 +220,13 @@ class BridgeSession(
val rawCanvasUrl = first["canvasHostUrl"].asStringOrNull()?.trim()?.ifEmpty { null } val rawCanvasUrl = first["canvasHostUrl"].asStringOrNull()?.trim()?.ifEmpty { null }
canvasHostUrl = normalizeCanvasHostUrl(rawCanvasUrl, endpoint) canvasHostUrl = normalizeCanvasHostUrl(rawCanvasUrl, endpoint)
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
android.util.Log.d( // Local JVM unit tests use android.jar stubs; Log.d can throw "not mocked".
"ClawdisBridge", runCatching {
"canvasHostUrl resolved=${canvasHostUrl ?: "none"} (raw=${rawCanvasUrl ?: "none"})", android.util.Log.d(
) "ClawdisBridge",
"canvasHostUrl resolved=${canvasHostUrl ?: "none"} (raw=${rawCanvasUrl ?: "none"})",
)
}
} }
onConnected(name, conn.remoteAddress) onConnected(name, conn.remoteAddress)
} }