Skip to content

Commit

Permalink
Merge pull request #38 from go-redis/fix/close_rate_limiter_loop
Browse files Browse the repository at this point in the history
rate_limit: break loop when pool is closed.
  • Loading branch information
vmihailenco committed Sep 4, 2014
2 parents 77d8805 + 1c2b863 commit 593d5d1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ func newConnPool(dial func() (*conn, error), opt *options) *connPool {

func (p *connPool) new() (*conn, error) {
select {
case <-p.rl.C:
case _, ok := <-p.rl.C:
if !ok {
return nil, errClosed
}
default:
return nil, errRateLimited
}
Expand Down Expand Up @@ -260,6 +263,7 @@ func (p *connPool) Close() error {
return nil
}
p.closed = true
close(p.rl.C)
var retErr error
for {
e := p.conns.Front()
Expand Down
3 changes: 3 additions & 0 deletions rate_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ func newRateLimiter(limit time.Duration, chanSize int) *rateLimiter {
}

func (rl *rateLimiter) loop(limit time.Duration) {
defer func() {
recover()
}()
for {
select {
case rl.C <- struct{}{}:
Expand Down

0 comments on commit 593d5d1

Please sign in to comment.