Fix switch failed start (#770)

This commit is contained in:
Tanguy 2022-09-15 09:06:32 +02:00 committed by GitHub
parent a001508490
commit 72abe822c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 6 deletions

View File

@ -312,12 +312,10 @@ proc start*(s: Switch) {.async, gcsafe, public.} =
await allFutures(startFuts)
for s in startFuts:
if s.failed:
# TODO: replace this exception with a `listenError` callback. See
# https://github.com/status-im/nim-libp2p/pull/662 for more info.
raise newException(transport.TransportError,
"Failed to start one transport", s.error)
for fut in startFuts:
if fut.failed:
await s.stop()
raise fut.error
for t in s.transports: # for each transport
if t.addrs.len > 0 or t.running:

View File

@ -1035,3 +1035,12 @@ suite "Switch":
await conn.close()
await src.stop()
await dst.stop()
asyncTest "switch failing to start stops properly":
let switch = newStandardSwitch(
addrs = @[MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet(), MultiAddress.init("/ip4/1.1.1.1/tcp/0").tryGet()]
)
expect LPError:
await switch.start()
# test is that this doesn't leak