Skip to content

Commit

Permalink
Return from waiting actions when a pool is closed
Browse files Browse the repository at this point in the history
Detect when a pool is closed while waiting for a connection to become
available and return an error. Otherwise the action gets stuck waiting
for a connection that won't appear and will only return when its
context's deadline is hit.
  • Loading branch information
Wade Smith authored and Brian Picciano committed Sep 6, 2023
1 parent a23d6b1 commit b91b732
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ func (p *pool) getConn(ctx context.Context) (*poolConn, error) {

select {
case <-p.notifyCh:
case <-p.proc.ClosedCh():
return nil, proc.ErrClosed
case <-ctx.Done():
return nil, ctx.Err()
}
Expand Down Expand Up @@ -426,6 +428,8 @@ func (p *pool) useSharedConn(ctx context.Context, a Action) error {

select {
case <-p.notifyCh:
case <-p.proc.ClosedCh():
return proc.ErrClosed
case <-ctx.Done():
return ctx.Err()
}
Expand Down

0 comments on commit b91b732

Please sign in to comment.