pool-queue-vs-stack pool should work like a queue to traverse all possible connections

pull/455/head
Anthony Regeda 2018-09-09 23:22:19 +03:00
parent e44f0f24c4
commit 00d38a68a8
No known key found for this signature in database
GPG Key ID: 1DCD928995BCB38F
1 changed files with 7 additions and 3 deletions

View File

@ -116,10 +116,14 @@ func (p *ConnPool) acquire(deadline *time.Time) (*Conn, error) {
}
// A connection is available
if len(p.availableConnections) > 0 {
c := p.availableConnections[len(p.availableConnections)-1]
// The pool works like a queue. Available connection will be returned
// from the head. A new connection will be added to the tail.
numAvailable := len(p.availableConnections)
if numAvailable > 0 {
c := p.availableConnections[0]
c.poolResetCount = p.resetCount
p.availableConnections = p.availableConnections[:len(p.availableConnections)-1]
copy(p.availableConnections, p.availableConnections[1:])
p.availableConnections = p.availableConnections[:numAvailable-1]
return c, nil
}