Skip to content

Commit

Permalink
rcmgr: remove a connection only once from the limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
sukunrt committed May 17, 2024
1 parent 547f9db commit 5423ce4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 0 additions & 1 deletion p2p/host/resource-manager/conn_limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func (cl *connLimiter) addConn(ip netip.Addr) bool {
return false
}
masked := prefix.String()

counts, ok := countsPerLimit[i][masked]
if !ok {
if countsPerLimit[i] == nil {
Expand Down
7 changes: 6 additions & 1 deletion p2p/host/resource-manager/rcmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,10 +677,15 @@ func (s *connectionScope) PeerScope() network.PeerScope {
}

func (s *connectionScope) Done() {
s.Lock()
defer s.Unlock()
if s.done {
return
}
if s.ip.IsValid() {
s.rcmgr.connLimiter.rmConn(s.ip)
}
s.resourceScope.Done()
s.resourceScope.doneUnlocked()
}

// transferAllowedToStandard transfers this connection scope from being part of
Expand Down
5 changes: 4 additions & 1 deletion p2p/host/resource-manager/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,10 +743,13 @@ func (s *resourceScope) Done() {
s.Lock()
defer s.Unlock()

s.doneUnlocked()
}

func (s *resourceScope) doneUnlocked() {
if s.done {
return
}

stat := s.rc.stat()
if s.owner != nil {
s.owner.ReleaseResources(stat)
Expand Down

0 comments on commit 5423ce4

Please sign in to comment.