From 47b486b52f850d3534b8a1e778fcf9cf40ffe7f6 Mon Sep 17 00:00:00 2001 From: Tanguy Date: Wed, 25 May 2022 16:02:46 +0200 Subject: [PATCH] Fix: handle simultaneous closing properly (#112) Since we use readFrame instead of readMsg, we need to handle it's possible exceptions. Closes #111 --- websock/session.nim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/websock/session.nim b/websock/session.nim index 6774193c00..70800df3b9 100644 --- a/websock/session.nim +++ b/websock/session.nim @@ -454,7 +454,11 @@ proc close*( opcode = Opcode.Close) # read frames until closed - while ws.readyState != ReadyState.Closed: - discard await ws.readFrame() + 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