From 5ec47677135cc0e1ce3a83202565c49a98f017fb Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 31 Mar 2020 08:57:02 -0700 Subject: [PATCH] fix: set teardown after storing the context. Otherwise, we can modify the context after/while the process is shutting down. fixes #189 --- swarm.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/swarm.go b/swarm.go index f85ef52..fe4e1ee 100644 --- a/swarm.go +++ b/swarm.go @@ -112,9 +112,13 @@ func NewSwarm(ctx context.Context, local peer.ID, peers peerstore.Peerstore, bwc s.dsync = NewDialSync(s.doDial) s.limiter = newDialLimiter(s.dialAddr) - s.proc = goprocessctx.WithContextAndTeardown(ctx, s.teardown) + s.proc = goprocessctx.WithContext(ctx) s.ctx = goprocessctx.OnClosingContext(s.proc) + // Set teardown after setting the context/process so we don't start the + // teardown process early. + s.proc.SetTeardown(s.teardown) + return s } -- GitLab