From 9c17ce2d9334bac1743c1ab18277b3397b4621e7 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Sat, 17 Jan 2015 11:56:34 +0200 Subject: [PATCH] Improve rate limited error message. --- pool.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/pool.go b/pool.go index bca4d196..ffedb3d5 100644 --- a/pool.go +++ b/pool.go @@ -3,6 +3,7 @@ package redis import ( "container/list" "errors" + "fmt" "log" "net" "sync" @@ -12,8 +13,7 @@ import ( ) var ( - errClosed = errors.New("redis: client is closed") - errRateLimited = errors.New("redis: you open connections too fast") + errClosed = errors.New("redis: client is closed") ) var ( @@ -100,6 +100,8 @@ type connPool struct { idleNum int closed bool + + lastDialErr error } func newConnPool(dial func() (*conn, error), opt *options) *connPool { @@ -116,9 +118,17 @@ func newConnPool(dial func() (*conn, error), opt *options) *connPool { func (p *connPool) new() (*conn, error) { if !p.rl.Check() { - return nil, errRateLimited + err := fmt.Errorf( + "redis: you open connections too fast (last error: %s)", + p.lastDialErr, + ) + return nil, err } - return p.dial() + cn, err := p.dial() + if err != nil { + p.lastDialErr = err + } + return cn, err } func (p *connPool) Get() (*conn, bool, error) {