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