client.go | 5 +++-- diff --git a/client.go b/client.go index f60a4607458bbb6a8c139ddeedffc42922b36e8e..dabf0de4e604740cc8e95f474308946f00ad4c51 100644 --- a/client.go +++ b/client.go @@ -733,7 +733,8 @@ delete(t.HalfOpen, addr) me.openNewConns(t) } -// Performs initiator handshakes and returns a connection. +// Performs initiator handshakes and returns a connection. Returns nil +// *connection if no connection for valid reasons. func (me *Client) handshakesConnection(nc net.Conn, t *torrent, encrypted, utp bool) (c *connection, err error) { c = newConnection() c.conn = nc @@ -782,7 +783,7 @@ err = fmt.Errorf("error dialing for unencrypted connection: %s", err) return } c, err = me.handshakesConnection(nc, t, false, utp) - if err != nil { + if err != nil || c == nil { nc.Close() } return