Handle graceful shutdown on TransportUseClosedError.
This commit is contained in:
parent
100f3188ed
commit
e45c6ede93
|
@ -223,6 +223,11 @@ proc upgradeMonitor(
|
||||||
finally:
|
finally:
|
||||||
upgrades.release()
|
upgrades.release()
|
||||||
|
|
||||||
|
proc accept_cleanup(upgrades: AsyncSemaphore, connection: Connection) {.async.} =
|
||||||
|
upgrades.release() # always release the slot
|
||||||
|
if not isNil(connection):
|
||||||
|
await connection.close()
|
||||||
|
|
||||||
proc accept(s: Switch, transport: Transport) {.async.} = # noraises
|
proc accept(s: Switch, transport: Transport) {.async.} = # noraises
|
||||||
## switch accept loop, ran for every transport
|
## switch accept loop, ran for every transport
|
||||||
##
|
##
|
||||||
|
@ -263,11 +268,12 @@ proc accept(s: Switch, transport: Transport) {.async.} = # noraises
|
||||||
trace "releasing semaphore on cancellation"
|
trace "releasing semaphore on cancellation"
|
||||||
upgrades.release() # always release the slot
|
upgrades.release() # always release the slot
|
||||||
return
|
return
|
||||||
|
except TransportUseClosedError:
|
||||||
|
await accept_cleanup(upgrades, conn)
|
||||||
|
return
|
||||||
except CatchableError as exc:
|
except CatchableError as exc:
|
||||||
error "Exception in accept loop, exiting", exc = exc.msg
|
error "Exception in accept loop, exiting", exc = exc.msg
|
||||||
upgrades.release() # always release the slot
|
await accept_cleanup(upgrades, conn)
|
||||||
if not isNil(conn):
|
|
||||||
await conn.close()
|
|
||||||
return
|
return
|
||||||
|
|
||||||
proc stop*(s: Switch) {.async, public.} =
|
proc stop*(s: Switch) {.async, public.} =
|
||||||
|
|
Loading…
Reference in New Issue