2
0

Connection pool timeout should return a consistent error value so clients can test for it.

This commit is contained in:
Alexander Staubo
2016-10-03 15:56:01 -04:00
parent ed2ab0a129
commit f1de186a93
+5 -2
View File
@@ -40,6 +40,9 @@ type ConnPoolStat struct {
AvailableConnections int // unused live connections
}
// ErrAcquireTimeout occurs when an attempt to acquire a connection times out.
var ErrAcquireTimeout = errors.New("timeout acquiring connection from pool")
// NewConnPool creates a new ConnPool. config.ConnConfig is passed through to
// Connect directly.
func NewConnPool(config ConnPoolConfig) (p *ConnPool, err error) {
@@ -131,7 +134,7 @@ func (p *ConnPool) acquire(deadline *time.Time) (*Conn, error) {
// Make sure the deadline (if it is) has not passed yet
if p.deadlinePassed(deadline) {
return nil, errors.New("Timeout: Acquire connection timeout")
return nil, ErrAcquireTimeout
}
// If there is a deadline then start a timeout timer
@@ -164,7 +167,7 @@ func (p *ConnPool) acquire(deadline *time.Time) (*Conn, error) {
// Wait until there is an available connection OR room to create a new connection
for len(p.availableConnections) == 0 && len(p.allConnections)+p.inProgressConnects == p.maxConnections {
if p.deadlinePassed(deadline) {
return nil, errors.New("Timeout: All connections in pool are busy")
return nil, ErrAcquireTimeout
}
p.cond.Wait()
}