Make sure process context is set last
License: MIT Signed-off-by: rht <rhtbot@gmail.com>
rht committed
Jul 5, 2015 at 09:35 UTC
3daf749daae5b14777a0491e6e3b97275d39c632
3 files changed
+5
-7
p2p/net/swarm/swarm_dial.go
+2
-2
@@ -17,6 +17,7 @@ import (
17
ma "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
18
manet "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net"
19
process "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess"
20
+ processctx "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess/context"
21
ratelimit "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess/ratelimit"
22
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
23
)
@@ -416,8 +417,7 @@ func (s *Swarm) dialAddrs(ctx context.Context, d *conn.Dialer, p peer.ID, remote
417
}
418
})
419
419
- <-ctx.Done()
420
- limiter.Close()
420
+ processctx.CloseAfterContext(limiter, ctx)
421
}()
422
423
// wair fot the results.
routing/dht/dht.go
+2
-1
@@ -73,7 +73,7 @@ func NewDHT(ctx context.Context, h host.Host, dstore ds.ThreadSafeDatastore) *Ip
73
// register for network notifs.
74
dht.host.Network().Notify((*netNotifiee)(dht))
75
76
- dht.proc = goprocessctx.WithContextAndTeardown(ctx, func() error {
76
+ dht.proc = goprocess.WithTeardown(func() error {
77
// remove ourselves from network notifs.
78
dht.host.Network().StopNotify((*netNotifiee)(dht))
79
return nil
@@ -84,6 +84,7 @@ func NewDHT(ctx context.Context, h host.Host, dstore ds.ThreadSafeDatastore) *Ip
84
h.SetStreamHandler(ProtocolDHT, dht.handleNewStream)
85
dht.providers = NewProviderManager(dht.ctx, dht.self)
86
dht.proc.AddChild(dht.providers.proc)
87
+ goprocessctx.CloseAfterContext(dht.proc, ctx)
88
89
dht.routingTable = kb.NewRoutingTable(20, kb.ConvertPeerID(dht.self), time.Minute, dht.peerstore)
90
dht.birth = time.Now()
routing/dht/query.go
+1
-4
@@ -127,10 +127,7 @@ func (r *dhtQueryRunner) Run(ctx context.Context, peers []peer.ID) (*dhtQueryRes
127
// now, if the context finishes, close the proc.
128
// we have to do it here because the logic before is setup, which
129
// should run without closing the proc.
130
- go func() {
131
- <-ctx.Done()
132
- r.proc.Close()
133
- }()
130
+ ctxproc.CloseAfterContext(r.proc, ctx)
131
132
select {
133
case <-r.peersRemaining.Done():