Skip to content

Commit 7d97cc1

Browse files
authored
feat: optimize connection pool waitTurn (#3412)
1 parent f4358ac commit 7d97cc1

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

internal/pool/pool.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,25 +325,23 @@ func (p *ConnPool) waitTurn(ctx context.Context) error {
325325

326326
start := time.Now()
327327
timer := timers.Get().(*time.Timer)
328+
defer timers.Put(timer)
328329
timer.Reset(p.cfg.PoolTimeout)
329330

330331
select {
331332
case <-ctx.Done():
332333
if !timer.Stop() {
333334
<-timer.C
334335
}
335-
timers.Put(timer)
336336
return ctx.Err()
337337
case p.queue <- struct{}{}:
338338
p.waitDurationNs.Add(time.Since(start).Nanoseconds())
339339
atomic.AddUint32(&p.stats.WaitCount, 1)
340340
if !timer.Stop() {
341341
<-timer.C
342342
}
343-
timers.Put(timer)
344343
return nil
345344
case <-timer.C:
346-
timers.Put(timer)
347345
atomic.AddUint32(&p.stats.Timeouts, 1)
348346
return ErrPoolTimeout
349347
}

0 commit comments

Comments
 (0)