Skip to content

Commit

Permalink
fix: open connection count (gomodule#527)
Browse files Browse the repository at this point in the history
This commit releases back the connection in the special
case, so that correct count is always maintained.
  • Loading branch information
rhnvrm authored Oct 26, 2020
1 parent a7bb38d commit bd964e5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions redis/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ func (p *Pool) waitVacantConn(ctx context.Context) (waited time.Duration, err er
// because `select` picks a random `case` if several of them are "ready".
select {
case <-ctx.Done():
p.ch <- struct{}{}
return 0, ctx.Err()
default:
}
Expand Down
26 changes: 26 additions & 0 deletions redis/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,32 @@ func TestWaitPoolGetContext(t *testing.T) {
defer c.Close()
}

func TestWaitPoolGetContextIssue520(t *testing.T) {
d := poolDialer{t: t}
p := &redis.Pool{
MaxIdle: 1,
MaxActive: 1,
Dial: d.dial,
Wait: true,
}
defer p.Close()
ctx1, cancel1 := context.WithTimeout(context.Background(), 1*time.Nanosecond)
defer cancel1()
c, err := p.GetContext(ctx1)
if err != context.DeadlineExceeded {
t.Fatalf("GetContext returned %v", err)
}
defer c.Close()

ctx2, cancel2 := context.WithCancel(context.Background())
defer cancel2()
c2, err := p.GetContext(ctx2)
if err != nil {
t.Fatalf("Get context returned %v", err)
}
defer c2.Close()
}

func TestWaitPoolGetContextWithDialContext(t *testing.T) {
d := poolDialer{t: t}
p := &redis.Pool{
Expand Down

0 comments on commit bd964e5

Please sign in to comment.