mirror of https://github.com/vacp2p/nim-libp2p.git
Transports: handle TransportAbortedError properly (#916)
This commit is contained in:
parent
a65b7b028f
commit
49dfa84c6f
|
@ -258,13 +258,8 @@ proc accept(s: Switch, transport: Transport) {.async.} = # noraises
|
||||||
if isNil(conn):
|
if isNil(conn):
|
||||||
# A nil connection means that we might have hit a
|
# A nil connection means that we might have hit a
|
||||||
# file-handle limit (or another non-fatal error),
|
# file-handle limit (or another non-fatal error),
|
||||||
# we can get one on the next try, but we should
|
# we can get one on the next try
|
||||||
# be careful to not end up in a thigh loop that
|
debug "Unable to get a connection"
|
||||||
# will starve the main event loop, thus we sleep
|
|
||||||
# here before retrying.
|
|
||||||
trace "Unable to get a connection, sleeping"
|
|
||||||
await sleepAsync(100.millis) # TODO: should be configurable?
|
|
||||||
upgrades.release()
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# set the direction of this bottom level transport
|
# set the direction of this bottom level transport
|
||||||
|
@ -278,7 +273,7 @@ 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
|
||||||
except CatchableError as exc:
|
except CatchableError as exc:
|
||||||
debug "Exception in accept loop, exiting", exc = exc.msg
|
error "Exception in accept loop, exiting", exc = exc.msg
|
||||||
upgrades.release() # always release the slot
|
upgrades.release() # always release the slot
|
||||||
if not isNil(conn):
|
if not isNil(conn):
|
||||||
await conn.close()
|
await conn.close()
|
||||||
|
|
|
@ -242,20 +242,20 @@ method accept*(self: TcpTransport): Future[Connection] {.async, gcsafe.} =
|
||||||
let transp = await finished
|
let transp = await finished
|
||||||
let observedAddr = await getObservedAddr(transp)
|
let observedAddr = await getObservedAddr(transp)
|
||||||
return await self.connHandler(transp, Opt.some(observedAddr), Direction.In)
|
return await self.connHandler(transp, Opt.some(observedAddr), Direction.In)
|
||||||
except TransportOsError as exc:
|
|
||||||
# TODO: it doesn't sound like all OS errors
|
|
||||||
# can be ignored, we should re-raise those
|
|
||||||
# that can'self.
|
|
||||||
debug "OS Error", exc = exc.msg
|
|
||||||
except TransportTooManyError as exc:
|
except TransportTooManyError as exc:
|
||||||
debug "Too many files opened", exc = exc.msg
|
debug "Too many files opened", exc = exc.msg
|
||||||
|
except TransportAbortedError as exc:
|
||||||
|
debug "Connection aborted", exc = exc.msg
|
||||||
except TransportUseClosedError as exc:
|
except TransportUseClosedError as exc:
|
||||||
debug "Server was closed", exc = exc.msg
|
debug "Server was closed", exc = exc.msg
|
||||||
raise newTransportClosedError(exc)
|
raise newTransportClosedError(exc)
|
||||||
except CancelledError as exc:
|
except CancelledError as exc:
|
||||||
raise exc
|
raise exc
|
||||||
|
except TransportOsError as exc:
|
||||||
|
info "OS Error", exc = exc.msg
|
||||||
|
raise exc
|
||||||
except CatchableError as exc:
|
except CatchableError as exc:
|
||||||
debug "Unexpected error accepting connection", exc = exc.msg
|
info "Unexpected error accepting connection", exc = exc.msg
|
||||||
raise exc
|
raise exc
|
||||||
|
|
||||||
method dial*(
|
method dial*(
|
||||||
|
|
|
@ -268,8 +268,6 @@ method accept*(self: WsTransport): Future[Connection] {.async, gcsafe.} =
|
||||||
except CatchableError as exc:
|
except CatchableError as exc:
|
||||||
await req.stream.closeWait()
|
await req.stream.closeWait()
|
||||||
raise exc
|
raise exc
|
||||||
except TransportOsError as exc:
|
|
||||||
debug "OS Error", exc = exc.msg
|
|
||||||
except WebSocketError as exc:
|
except WebSocketError as exc:
|
||||||
debug "Websocket Error", exc = exc.msg
|
debug "Websocket Error", exc = exc.msg
|
||||||
except HttpError as exc:
|
except HttpError as exc:
|
||||||
|
@ -284,10 +282,12 @@ method accept*(self: WsTransport): Future[Connection] {.async, gcsafe.} =
|
||||||
debug "Server was closed", exc = exc.msg
|
debug "Server was closed", exc = exc.msg
|
||||||
raise newTransportClosedError(exc)
|
raise newTransportClosedError(exc)
|
||||||
except CancelledError as exc:
|
except CancelledError as exc:
|
||||||
# bubble up silently
|
raise exc
|
||||||
|
except TransportOsError as exc:
|
||||||
|
info "OS Error", exc = exc.msg
|
||||||
raise exc
|
raise exc
|
||||||
except CatchableError as exc:
|
except CatchableError as exc:
|
||||||
warn "Unexpected error accepting connection", exc = exc.msg
|
info "Unexpected error accepting connection", exc = exc.msg
|
||||||
raise exc
|
raise exc
|
||||||
|
|
||||||
method dial*(
|
method dial*(
|
||||||
|
|
Loading…
Reference in New Issue