Skip to content

Commit

Permalink
Swap the ordering of when teardown and ctx is set
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: rht <[email protected]>
  • Loading branch information
rht committed Jul 4, 2015
1 parent 6721ec9 commit f7b7226
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 11 deletions.
6 changes: 2 additions & 4 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,13 @@ func NewIPFSNode(ctx context.Context, option ConfigOption) (*IpfsNode, error) {
return nil, err
}

proc := goprocessctx.WithContext(ctx)
proc.SetTeardown(node.teardown)
node.proc = proc
node.proc = goprocessctx.WithContextAndTeardown(ctx, node.teardown)
node.ctx = ctx

success := false // flip to true after all sub-system inits succeed
defer func() {
if !success {
proc.Close()
node.proc.Close()
}
}()

Expand Down
3 changes: 1 addition & 2 deletions p2p/net/mock/mock_peernet.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,14 @@ func newPeernet(ctx context.Context, m *mocknet, k ic.PrivKey,
mocknet: m,
peer: p,
ps: ps,
proc: goprocessctx.WithContext(ctx),

connsByPeer: map[peer.ID]map[*conn]struct{}{},
connsByLink: map[*link]map[*conn]struct{}{},

notifs: make(map[inet.Notifiee]struct{}),
}

n.proc.SetTeardown(n.teardown)
n.proc = goprocessctx.WithContextAndTeardown(ctx, n.teardown)
return n, nil
}

Expand Down
3 changes: 1 addition & 2 deletions p2p/net/swarm/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr,
swarm: ps.NewSwarm(PSTransport),
local: local,
peers: peers,
proc: goprocessctx.WithContext(ctx),
ctx: ctx,
dialT: DialTimeout,
notifs: make(map[inet.Notifiee]ps.Notifiee),
Expand All @@ -91,7 +90,7 @@ func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr,
}

// configure Swarm
s.proc.SetTeardown(s.teardown)
s.proc = goprocessctx.WithContextAndTeardown(ctx, s.teardown)
s.SetConnHandler(nil) // make sure to setup our own conn handler.

// setup swarm metrics
Expand Down
5 changes: 2 additions & 3 deletions routing/dht/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,12 @@ func NewDHT(ctx context.Context, h host.Host, dstore ds.ThreadSafeDatastore) *Ip
// register for network notifs.
dht.host.Network().Notify((*netNotifiee)(dht))

proc := goprocessctx.WithContext(ctx)
proc.SetTeardown(func() error {
dht.proc = goprocessctx.WithContextAndTeardown(ctx, func() error {
// remove ourselves from network notifs.
dht.host.Network().StopNotify((*netNotifiee)(dht))
return nil
})
dht.proc = proc

dht.ctx = ctx

h.SetStreamHandler(ProtocolDHT, dht.handleNewStream)
Expand Down

0 comments on commit f7b7226

Please sign in to comment.