]> Sergey Matveev's repositories - btrtrc.git/blobdiff - peerconn.go
Avoid calling net.Conn methods with the Client mutex locked
[btrtrc.git] / peerconn.go
index 9a3fb0fc0491bc0f6a75dd96f02ab1cb4cdfc488..bd0bce2e47e1ee50bbb3e241f1c9a381772a9842 100644 (file)
@@ -138,7 +138,8 @@ type PeerConn struct {
        PeerID             PeerID
        PeerExtensionBytes pp.PeerExtensionBits
 
-       // The actual Conn, used for closing, and setting socket options.
+       // The actual Conn, used for closing, and setting socket options. Do not use methods on this
+       // while holding any mutexes.
        conn net.Conn
        // The Reader and Writer for this Conn, with hooks installed for stats,
        // limiting, deadlines etc.
@@ -426,7 +427,7 @@ func (cn *PeerConn) onClose() {
        }
        cn.tickleWriter()
        if cn.conn != nil {
-               cn.conn.Close()
+               go cn.conn.Close()
        }
        if cb := cn.callbacks.PeerConnClosed; cb != nil {
                cb(cn)