Starting switch two times does not crash (#810)
This commit is contained in:
parent
1711c204ea
commit
b3d9360dfc
|
@ -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:
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in New Issue