mirror of
https://github.com/vacp2p/nim-libp2p.git
synced 2026-01-09 02:38:19 -05:00
fix: do not use while loop for quic transport errors (#1317)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user