Skip to content

Commit

Permalink
Release lock before attempting to close a connection (ava-labs#2481)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Jan 17, 2023
1 parent 92690ac commit bab4af5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -1135,9 +1135,9 @@ func (n *network) upgrade(conn net.Conn, upgrader peer.Upgrader) error {
}

n.peersLock.Lock()
defer n.peersLock.Unlock()

if n.closing {
n.peersLock.Unlock()

_ = tlsConn.Close()
n.peerConfig.Log.Verbo(
"dropping connection",
Expand All @@ -1148,6 +1148,8 @@ func (n *network) upgrade(conn net.Conn, upgrader peer.Upgrader) error {
}

if _, connecting := n.connectingPeers.GetByID(nodeID); connecting {
n.peersLock.Unlock()

_ = tlsConn.Close()
n.peerConfig.Log.Verbo(
"dropping connection",
Expand All @@ -1158,6 +1160,8 @@ func (n *network) upgrade(conn net.Conn, upgrader peer.Upgrader) error {
}

if _, connected := n.connectedPeers.GetByID(nodeID); connected {
n.peersLock.Unlock()

_ = tlsConn.Close()
n.peerConfig.Log.Verbo(
"dropping connection",
Expand Down Expand Up @@ -1194,6 +1198,7 @@ func (n *network) upgrade(conn net.Conn, upgrader peer.Upgrader) error {
),
)
n.connectingPeers.Add(peer)
n.peersLock.Unlock()
return nil
}

Expand Down

0 comments on commit bab4af5

Please sign in to comment.