From f8704e4b6b43ad8e687c926a0235c6e33dfc4a64 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Sun, 9 Jun 2019 12:29:23 +0300 Subject: [PATCH] Cleanup --- internal/pool/conn.go | 7 +++---- internal/pool/pool.go | 4 ++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/internal/pool/conn.go b/internal/pool/conn.go index 687c1e8..32d1cd4 100644 --- a/internal/pool/conn.go +++ b/internal/pool/conn.go @@ -82,20 +82,19 @@ func (cn *Conn) Close() error { } func (cn *Conn) deadline(ctx context.Context, timeout time.Duration) time.Time { + now := time.Now() + cn.SetUsedAt(now) + if ctx != nil { tm, ok := ctx.Deadline() if ok { - cn.SetUsedAt(tm) return tm } } - now := time.Now() if timeout > 0 { - cn.SetUsedAt(now) return now.Add(timeout) } - cn.SetUsedAt(now) return noDeadline } diff --git a/internal/pool/pool.go b/internal/pool/pool.go index 013e29b..1094a5b 100644 --- a/internal/pool/pool.go +++ b/internal/pool/pool.go @@ -265,6 +265,10 @@ func (p *ConnPool) waitTurn(ctx context.Context) error { select { case <-done: + if !timer.Stop() { + <-timer.C + } + timers.Put(timer) return ctx.Err() case p.queue <- struct{}{}: if !timer.Stop() {