Fix: handle simultaneous closing properly (#112)

Since we use readFrame instead of readMsg, we need to handle
it's possible exceptions. Closes #111
This commit is contained in:
Tanguy 2022-05-25 16:02:46 +02:00 committed by GitHub
parent 8927db93f6
commit 47b486b52f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -454,7 +454,11 @@ proc close*(
opcode = Opcode.Close)
# read frames until closed
try:
while ws.readyState != ReadyState.Closed:
discard await ws.readFrame()
except CatchableError as exc:
ws.readyState = ReadyState.Closed
await ws.stream.closeWait()
except CatchableError as exc:
trace "Exception closing", exc = exc.msg