From: Matt Joiner Date: Sun, 11 Aug 2019 03:17:47 +0000 (+1000) Subject: Don't include the handshake in the dial timeout for outgoing connections X-Git-Tag: v1.6.0~2 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=6013f09f8a7c3d96ae3e5bba5bff455467232029;p=btrtrc.git Don't include the handshake in the dial timeout for outgoing connections --- diff --git a/client.go b/client.go index f8a4a151..a3d6fca4 100644 --- a/client.go +++ b/client.go @@ -632,21 +632,21 @@ func (cl *Client) handshakesConnection(ctx context.Context, nc net.Conn, t *Torr // Returns nil connection and nil error if no connection could be established // for valid reasons. func (cl *Client) establishOutgoingConnEx(t *Torrent, addr IpPort, obfuscatedHeader bool) (*connection, error) { - ctx, cancel := context.WithTimeout(context.Background(), func() time.Duration { + dialCtx, cancel := context.WithTimeout(context.Background(), func() time.Duration { cl.rLock() defer cl.rUnlock() return t.dialTimeout() }()) defer cancel() - dr := cl.dialFirst(ctx, addr.String()) + dr := cl.dialFirst(dialCtx, addr.String()) nc := dr.Conn if nc == nil { - if ctx.Err() != nil { - return nil, ctx.Err() + if dialCtx.Err() != nil { + return nil, xerrors.Errorf("dialing: %w", dialCtx.Err()) } return nil, errors.New("dial failed") } - c, err := cl.handshakesConnection(ctx, nc, t, obfuscatedHeader, addr, dr.Network) + c, err := cl.handshakesConnection(context.Background(), nc, t, obfuscatedHeader, addr, dr.Network) if err != nil { nc.Close() }