]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix race condition calculating reduced dial timeout
authorMatt Joiner <anacrolix@gmail.com>
Tue, 18 Nov 2014 20:33:07 +0000 (14:33 -0600)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 18 Nov 2014 20:33:07 +0000 (14:33 -0600)
client.go

index 0c9ff2e5e49c27f333d4983f0e3915fbba81ab36..3979b3967195315d4204adfaf2b3d425832268c0 100644 (file)
--- a/client.go
+++ b/client.go
@@ -409,6 +409,7 @@ func (me *Client) initiateConn(peer Peer, t *torrent) {
                duplicateConnsAvoided.Add(1)
                return
        }
+       dialTimeout := reducedDialTimeout(dialTimeout, me.halfOpenLimit, len(t.Peers))
        t.HalfOpen[addr] = struct{}{}
        go func() {
                // Binding to the listen address and dialing via net.Dialer gives
@@ -416,7 +417,6 @@ func (me *Client) initiateConn(peer Peer, t *torrent) {
                // this address so that peers associate our local address with our
                // listen address.
 
-               dialTimeout := reducedDialTimeout(dialTimeout, me.halfOpenLimit, len(t.Peers))
                // Initiate connections via TCP and UTP simultaneously. Use the first
                // one that succeeds.
                left := 2