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 7b912ed
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion p2p/host/resource-manager/conn_limiter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rcmgr

import (
"fmt"

Check failure on line 4 in p2p/host/resource-manager/conn_limiter.go

View workflow job for this annotation

GitHub Actions / go-test / macos (go 1.21.x)

"fmt" imported and not used

Check failure on line 4 in p2p/host/resource-manager/conn_limiter.go

View workflow job for this annotation

GitHub Actions / go-test / macos (go 1.22.x)

"fmt" imported and not used

Check failure on line 4 in p2p/host/resource-manager/conn_limiter.go

View workflow job for this annotation

GitHub Actions / go-check / All

"fmt" imported and not used

Check failure on line 4 in p2p/host/resource-manager/conn_limiter.go

View workflow job for this annotation

GitHub Actions / go-check / All

"fmt" imported and not used (compile)

Check failure on line 4 in p2p/host/resource-manager/conn_limiter.go

View workflow job for this annotation

GitHub Actions / go-check / All

"fmt" imported and not used (compile)
"net/netip"
"sync"
)
Expand Down Expand Up @@ -85,7 +86,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 7b912ed

Please sign in to comment.