@cryptotaxi247 / kubo / commits / dfdf346b2

fix weird race condition in goprocess that caused a few panics

Jeromy committed Feb 19, 2015 at 20:01 UTC dfdf346b225ef9cfe5de0d917c08f9cd797a4cfe
1 file changed +4 -2
p2p/net/swarm/swarm_dial.go
+4 -2
@@ -17,7 +17,6 @@ import (
17 ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
18 manet "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net"
19 process "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess"
20 - procctx "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess/context"
20 ratelimit "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess/ratelimit"
21 )
22
@@ -384,7 +383,7 @@ func (s *Swarm) dialAddrs(ctx context.Context, d *conn.Dialer, p peer.ID, remote
383 // to end early.
384 go func() {
385 // rate limiting just in case. at most 10 addrs at once.
387 - limiter := ratelimit.NewRateLimiter(procctx.WithContext(ctx), 10)
386 + limiter := ratelimit.NewRateLimiter(process.Background(), 10)
387 limiter.Go(func(worker process.Process) {
388 // permute addrs so we try different sets first each time.
389 for _, i := range rand.Perm(len(remoteAddrs)) {
@@ -402,6 +401,9 @@ func (s *Swarm) dialAddrs(ctx context.Context, d *conn.Dialer, p peer.ID, remote
401 })
402 }
403 })
404 +
405 + <-ctx.Done()
406 + limiter.Close()
407 }()
408
409 // wair fot the results.