From e929d5431d1b48b34c84d3b2c875b359c8be2ea1 Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Fri, 23 Jun 2023 17:39:13 +0200 Subject: [PATCH] correct throttle counting --- net/peer/peer.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/net/peer/peer.go b/net/peer/peer.go index b96162f7..9ff7f023 100644 --- a/net/peer/peer.go +++ b/net/peer/peer.go @@ -79,9 +79,10 @@ type peer struct { // drpc conn pool // outgoing - inactive []*subConn - active map[*subConn]struct{} - subConnRelease chan drpc.Conn + inactive []*subConn + active map[*subConn]struct{} + subConnRelease chan drpc.Conn + openingWaitCount atomic.Int32 incomingCount atomic.Int32 acceptCtx context.Context @@ -103,9 +104,11 @@ func (p *peer) Id() string { func (p *peer) AcquireDrpcConn(ctx context.Context) (drpc.Conn, error) { p.mu.Lock() if len(p.inactive) == 0 { - wait := p.limiter.wait(len(p.active)) + wait := p.limiter.wait(len(p.active) + int(p.openingWaitCount.Load())) p.mu.Unlock() if wait != nil { + p.openingWaitCount.Add(1) + defer p.openingWaitCount.Add(-1) // throttle new connection opening select { case <-ctx.Done():