avoid `KeyError` in edge case of yamux handler (#1044)

This commit is contained in:
Etan Kissling 2024-03-04 00:24:18 +01:00 committed by GitHub
parent ee264fdf11
commit 18e00a741b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 1 deletions

View File

@ -528,7 +528,12 @@ method handle*(m: Yamux) {.async.} =
await m.connection.readExactly(addr buffer[0], int(header.length))
continue
let channel = m.channels[header.streamId]
let channel =
try:
m.channels[header.streamId]
except KeyError:
raise newException(YamuxError,
"Stream was cleaned up before handling data: " & $header.streamId)
if header.msgType == WindowUpdate:
channel.sendWindow += int(header.length)