From 224f92e17251464984d6906316c54d2e1108ae43 Mon Sep 17 00:00:00 2001 From: Tanguy Date: Tue, 20 Jun 2023 16:18:49 +0200 Subject: [PATCH] Fix #916 regression causing accept loop lockup (#919) --- libp2p/switch.nim | 1 + libp2p/transports/tcptransport.nim | 13 ++----------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/libp2p/switch.nim b/libp2p/switch.nim index ee9e837a37..dabbc2f700 100644 --- a/libp2p/switch.nim +++ b/libp2p/switch.nim @@ -260,6 +260,7 @@ proc accept(s: Switch, transport: Transport) {.async.} = # noraises # file-handle limit (or another non-fatal error), # we can get one on the next try debug "Unable to get a connection" + upgrades.release() continue # set the direction of this bottom level transport diff --git a/libp2p/transports/tcptransport.nim b/libp2p/transports/tcptransport.nim index b8891e0ef7..18dd235fe8 100644 --- a/libp2p/transports/tcptransport.nim +++ b/libp2p/transports/tcptransport.nim @@ -72,15 +72,6 @@ proc setupTcpTransportTracker(): TcpTransportTracker = result.isLeaked = leakTransport addTracker(TcpTransportTrackerName, result) -proc getObservedAddr(client: StreamTransport): Future[MultiAddress] {.async.} = - try: - return MultiAddress.init(client.remoteAddress).tryGet() - except CatchableError as exc: - trace "Failed to create observedAddr", exc = exc.msg - if not(isNil(client) and client.closed): - await client.closeWait() - raise exc - proc connHandler*(self: TcpTransport, client: StreamTransport, observedAddr: Opt[MultiAddress], @@ -241,7 +232,7 @@ method accept*(self: TcpTransport): Future[Connection] {.async, gcsafe.} = let transp = await finished try: - let observedAddr = await getObservedAddr(transp) + let observedAddr = MultiAddress.init(transp.remoteAddress).tryGet() return await self.connHandler(transp, Opt.some(observedAddr), Direction.In) except CancelledError as exc: transp.close() @@ -282,7 +273,7 @@ method dial*( await connect(address, flags = self.clientFlags) try: - let observedAddr = await getObservedAddr(transp) + let observedAddr = MultiAddress.init(transp.remoteAddress).tryGet() return await self.connHandler(transp, Opt.some(observedAddr), Direction.Out) except CatchableError as err: await transp.closeWait()