mirror of https://github.com/go-redis/redis.git
Merge pull request #38 from go-redis/fix/close_rate_limiter_loop
rate_limit: break loop when pool is closed.
This commit is contained in:
commit
593d5d1d77
6
pool.go
6
pool.go
|
@ -116,7 +116,10 @@ func newConnPool(dial func() (*conn, error), opt *options) *connPool {
|
||||||
|
|
||||||
func (p *connPool) new() (*conn, error) {
|
func (p *connPool) new() (*conn, error) {
|
||||||
select {
|
select {
|
||||||
case <-p.rl.C:
|
case _, ok := <-p.rl.C:
|
||||||
|
if !ok {
|
||||||
|
return nil, errClosed
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return nil, errRateLimited
|
return nil, errRateLimited
|
||||||
}
|
}
|
||||||
|
@ -260,6 +263,7 @@ func (p *connPool) Close() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
p.closed = true
|
p.closed = true
|
||||||
|
close(p.rl.C)
|
||||||
var retErr error
|
var retErr error
|
||||||
for {
|
for {
|
||||||
e := p.conns.Front()
|
e := p.conns.Front()
|
||||||
|
|
|
@ -20,6 +20,9 @@ func newRateLimiter(limit time.Duration, chanSize int) *rateLimiter {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rl *rateLimiter) loop(limit time.Duration) {
|
func (rl *rateLimiter) loop(limit time.Duration) {
|
||||||
|
defer func() {
|
||||||
|
recover()
|
||||||
|
}()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case rl.C <- struct{}{}:
|
case rl.C <- struct{}{}:
|
||||||
|
|
Loading…
Reference in New Issue