Slightly janky fix for send failure instantly cancelling SolarXR scope

Closes #1974
This commit is contained in:
Sapphire committed 2026-12-06 04:15:39 -05:00
1 parent b81fa39499
commit 49016f4ca3
1 file changed
+8 -1
@@ -101,8 +101,15 @@ suspend fun handleSolarXRBridge(
// share: this collector handles one bundle at a time, and send drains the buffer
val fbb = FlatBufferBuilder(256)
val sendBuffer = Buffer()
// If a client connected, sent a message, then immediately disconnected, we want to
// stop trying to write but still read the last message, so we can't cancel immediately.
// We'll end up dropping the connection since the messages flow finishes collection
// when an error happens
var writeFailed = false
bridge.outbound.on<MessageBundle> { bundle ->
if (writeFailed) return@on
fbb.clear()
fbb.finish(bundle.encode(JvmFlatBufferWriter(fbb)))
sendBuffer.write(fbb.dataBuffer())
@@ -110,7 +117,7 @@ suspend fun handleSolarXRBridge(
send(sendBuffer)
} catch (e: IOException) {
AppLogger.solarxr.warn("Exception when sending bundle to $name: ${e.message}")
cancel()
writeFailed = true
}
}.launchIn(this)