Skip to content

Commit

Permalink
Fix #916 regression causing accept loop lockup (#919)
Browse files Browse the repository at this point in the history
  • Loading branch information
Menduist authored Jun 20, 2023
1 parent 5efa089 commit 224f92e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
1 change: 1 addition & 0 deletions libp2p/switch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 2 additions & 11 deletions libp2p/transports/tcptransport.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 224f92e

Please sign in to comment.