This commit is contained in:
Vladimir Mihailenco 2019-06-09 12:29:23 +03:00
parent 3d8a511ecc
commit f8704e4b6b
2 changed files with 7 additions and 4 deletions

View File

@ -82,20 +82,19 @@ func (cn *Conn) Close() error {
} }
func (cn *Conn) deadline(ctx context.Context, timeout time.Duration) time.Time { func (cn *Conn) deadline(ctx context.Context, timeout time.Duration) time.Time {
now := time.Now()
cn.SetUsedAt(now)
if ctx != nil { if ctx != nil {
tm, ok := ctx.Deadline() tm, ok := ctx.Deadline()
if ok { if ok {
cn.SetUsedAt(tm)
return tm return tm
} }
} }
now := time.Now()
if timeout > 0 { if timeout > 0 {
cn.SetUsedAt(now)
return now.Add(timeout) return now.Add(timeout)
} }
cn.SetUsedAt(now)
return noDeadline return noDeadline
} }

View File

@ -265,6 +265,10 @@ func (p *ConnPool) waitTurn(ctx context.Context) error {
select { select {
case <-done: case <-done:
if !timer.Stop() {
<-timer.C
}
timers.Put(timer)
return ctx.Err() return ctx.Err()
case p.queue <- struct{}{}: case p.queue <- struct{}{}:
if !timer.Stop() { if !timer.Stop() {