Skip to content

Commit

Permalink
Transports: handle TransportAbortedError properly (#916)
Browse files Browse the repository at this point in the history
  • Loading branch information
Menduist authored Jun 14, 2023
1 parent a65b7b0 commit 49dfa84
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
11 changes: 3 additions & 8 deletions libp2p/switch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,8 @@ proc accept(s: Switch, transport: Transport) {.async.} = # noraises
if isNil(conn):
# A nil connection means that we might have hit a
# file-handle limit (or another non-fatal error),
# we can get one on the next try, but we should
# be careful to not end up in a thigh loop that
# 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()
# we can get one on the next try
debug "Unable to get a connection"
continue

# set the direction of this bottom level transport
Expand All @@ -278,7 +273,7 @@ proc accept(s: Switch, transport: Transport) {.async.} = # noraises
trace "releasing semaphore on cancellation"
upgrades.release() # always release the slot
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
if not isNil(conn):
await conn.close()
Expand Down
12 changes: 6 additions & 6 deletions libp2p/transports/tcptransport.nim
Original file line number Diff line number Diff line change
Expand Up @@ -242,20 +242,20 @@ method accept*(self: TcpTransport): Future[Connection] {.async, gcsafe.} =
let transp = await finished
let observedAddr = await getObservedAddr(transp)
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:
debug "Too many files opened", exc = exc.msg
except TransportAbortedError as exc:
debug "Connection aborted", exc = exc.msg
except TransportUseClosedError as exc:
debug "Server was closed", exc = exc.msg
raise newTransportClosedError(exc)
except CancelledError as exc:
raise exc
except TransportOsError as exc:
info "OS Error", exc = exc.msg
raise exc
except CatchableError as exc:
debug "Unexpected error accepting connection", exc = exc.msg
info "Unexpected error accepting connection", exc = exc.msg
raise exc

method dial*(
Expand Down
8 changes: 4 additions & 4 deletions libp2p/transports/wstransport.nim
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,6 @@ method accept*(self: WsTransport): Future[Connection] {.async, gcsafe.} =
except CatchableError as exc:
await req.stream.closeWait()
raise exc
except TransportOsError as exc:
debug "OS Error", exc = exc.msg
except WebSocketError as exc:
debug "Websocket Error", exc = exc.msg
except HttpError as exc:
Expand All @@ -284,10 +282,12 @@ method accept*(self: WsTransport): Future[Connection] {.async, gcsafe.} =
debug "Server was closed", exc = exc.msg
raise newTransportClosedError(exc)
except CancelledError as exc:
# bubble up silently
raise exc
except TransportOsError as exc:
info "OS Error", exc = exc.msg
raise exc
except CatchableError as exc:
warn "Unexpected error accepting connection", exc = exc.msg
info "Unexpected error accepting connection", exc = exc.msg
raise exc

method dial*(
Expand Down

0 comments on commit 49dfa84

Please sign in to comment.