Skip to content

Commit

Permalink
Starting switch two times does not crash
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomrsantos committed Nov 29, 2022
1 parent 1711c20 commit 4731573
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions libp2p/switch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions tests/testswitch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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())

0 comments on commit 4731573

Please sign in to comment.