Starting switch two times does not crash (#810)

This commit is contained in:
diegomrsantos 2022-11-29 16:21:51 +01:00 committed by GitHub
parent 1711c204ea
commit b3d9360dfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -296,6 +296,10 @@ proc stop*(s: Switch) {.async, public.} =
proc start*(s: Switch) {.async, gcsafe, public.} =
## Start listening on every transport
if s.started:
warn "Switch has already been started"
return
trace "starting switch for peer", peerInfo = s.peerInfo
var startFuts: seq[Future[void]]
for t in s.transports:

View File

@ -1016,3 +1016,13 @@ suite "Switch":
expect LPError:
await switch.start()
# test is that this doesn't leak
asyncTest "starting two times does not crash":
let switch = newStandardSwitch(
addrs = @[MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet()]
)
await switch.start()
await switch.start()
await allFuturesThrowing(switch.stop())