Skip to content

Commit

Permalink
fix: trim connections every gracePeriod/2
Browse files Browse the repository at this point in the history
We're still rate-limited to once every 10 seconds. However, this means that
setting the grace period to something below one minute actually _does_ something
useful.

fixes #51
  • Loading branch information
Stebalien committed Jul 30, 2019
1 parent d7ecbe5 commit b200369
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion p2p/net/connmgr/connmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,15 @@ func (cm *BasicConnMgr) TrimOpenConns(ctx context.Context) {
}

func (cm *BasicConnMgr) background() {
ticker := time.NewTicker(time.Minute)
interval := cm.gracePeriod / 2
if interval < cm.silencePeriod {
interval = cm.silencePeriod
}
if interval < 10*time.Second {
interval = 10 * time.Second
}

ticker := time.NewTicker(interval)
defer ticker.Stop()

for {
Expand Down

0 comments on commit b200369

Please sign in to comment.