fix: do not use while loop for quic transport errors (#1317)

This commit is contained in:
richΛrd
2025-04-10 17:47:42 -04:00
committed by GitHub
parent 5ddd62a8b9
commit 0f91b23f12
2 changed files with 20 additions and 16 deletions

View File

@@ -255,7 +255,7 @@ method stop*(transport: QuicTransport) {.async: (raises: []).} =
proc wrapConnection(
transport: QuicTransport, connection: QuicConnection
): QuicSession {.raises: [TransportOsError, LPError].} =
): QuicSession {.raises: [TransportOsError, MaError].} =
let
remoteAddr = connection.remoteAddress()
observedAddr =
@@ -283,22 +283,23 @@ method accept*(
.} =
doAssert not self.listener.isNil, "call start() before calling accept()"
while true:
if not self.running:
# stop accept only when transport is stopped (not when error occurs)
raise newException(QuicTransportAcceptStopped, "Quic transport stopped")
if not self.running:
# stop accept only when transport is stopped (not when error occurs)
raise newException(QuicTransportAcceptStopped, "Quic transport stopped")
try:
let connection = await self.listener.accept()
return self.wrapConnection(connection)
except CancelledError as e:
raise e
except QuicError as e:
trace "Quic accept connection error", msg = e.msg
# swallow all errors and continue accepting until connection is established
continue
except CatchableError as e:
raise (ref QuicTransportError)(msg: e.msg, parent: e)
try:
let connection = await self.listener.accept()
return self.wrapConnection(connection)
except CancelledError as exc:
raise exc
except QuicError as exc:
debug "Quic Error", description = exc.msg
except MaError as exc:
debug "Multiaddr Error", description = exc.msg
except CatchableError as exc: # TODO: removing this requires async/raises in nim-quic
info "Unexpected error accepting quic connection", description = exc.msg
except TransportOsError as exc:
debug "OS Error", description = exc.msg
method dial*(
self: QuicTransport,

View File

@@ -24,6 +24,9 @@ proc createServerAcceptConn(
.} =
try:
let conn = await server.accept()
if conn == nil:
return
let stream = await getStream(QuicSession(conn), Direction.In)
var resp: array[6, byte]
await stream.readExactly(addr resp, 6)