Skip to content

Commit

Permalink
Merge pull request #207 from libp2p/fix/pstore-close-race
Browse files Browse the repository at this point in the history
fix: avoid calling AddChild after the process may shutdown.
  • Loading branch information
Stebalien committed Apr 23, 2020
2 parents 5811140 + 9b8dbb7 commit 47faf65
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion p2p/net/swarm/testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ func GenSwarm(t *testing.T, ctx context.Context, opts ...Option) *swarm.Swarm {
ps.AddPubKey(p.ID, p.PubKey)
ps.AddPrivKey(p.ID, p.PrivKey)
s := swarm.NewSwarm(ctx, p.ID, ps, metrics.NewBandwidthCounter())
s.Process().AddChild(goprocess.WithTeardown(ps.Close))
// Call AddChildNoWait because we can't call AddChild after the process
// may have been closed (e.g., if the context was canceled).
s.Process().AddChildNoWait(goprocess.WithTeardown(ps.Close))

tcpTransport := tcp.NewTCPTransport(GenUpgrader(s))
tcpTransport.DisableReuseport = cfg.disableReuseport
Expand Down

0 comments on commit 47faf65

Please sign in to comment.