Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

fix: shard lock to fix contention issue in the notify handler #561

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions internal/decision/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -914,20 +914,20 @@ func (e *Engine) MessageSent(p peer.ID, m bsmsg.BitSwapMessage) {
// sending blocks.
func (e *Engine) PeerConnected(p peer.ID) {
e.lock.Lock()
defer e.lock.Unlock()

_, ok := e.ledgerMap[p]
if !ok {
e.ledgerMap[p] = newLedger(p)
}

e.lock.Unlock()

e.scoreLedger.PeerConnected(p)
}

// PeerDisconnected is called when a peer disconnects.
func (e *Engine) PeerDisconnected(p peer.ID) {
e.lock.Lock()
defer e.lock.Unlock()

ledger, ok := e.ledgerMap[p]
if ok {
Expand All @@ -941,6 +941,8 @@ func (e *Engine) PeerDisconnected(p peer.ID) {
}
delete(e.ledgerMap, p)

e.lock.Unlock()

e.scoreLedger.PeerDisconnected(p)
}

Expand Down
10 changes: 7 additions & 3 deletions network/connecteventmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func newConnectEventManager(connListener ConnectionListener) *connectEventManage

func (c *connectEventManager) Connected(p peer.ID) {
c.lk.Lock()
defer c.lk.Unlock()

state, ok := c.conns[p]
if !ok {
Expand All @@ -41,13 +40,15 @@ func (c *connectEventManager) Connected(p peer.ID) {
state.refs++

if state.refs == 1 && state.responsive {
c.lk.Unlock()
c.connListener.PeerConnected(p)
return
}
c.lk.Unlock()
}

func (c *connectEventManager) Disconnected(p peer.ID) {
c.lk.Lock()
defer c.lk.Unlock()

state, ok := c.conns[p]
if !ok {
Expand All @@ -57,11 +58,14 @@ func (c *connectEventManager) Disconnected(p peer.ID) {
state.refs--

if state.refs == 0 {
delete(c.conns, p)
if state.responsive {
c.lk.Unlock()
c.connListener.PeerDisconnected(p)
return
}
delete(c.conns, p)
}
c.lk.Unlock()
}

func (c *connectEventManager) MarkUnresponsive(p peer.ID) {
Expand Down