Skip to content

drpcpool: close connections returned to a closed pool#60

Open
shubhamdhama wants to merge 1 commit into
cockroachdb:mainfrom
shubhamdhama:pool-put-after-close
Open

drpcpool: close connections returned to a closed pool#60
shubhamdhama wants to merge 1 commit into
cockroachdb:mainfrom
shubhamdhama:pool-put-after-close

Conversation

@shubhamdhama

Copy link
Copy Markdown

Pool.Close only sees the connections currently idle in the cache. Connections that are checked out serving an in-flight Invoke or NewStream live outside the cache and are returned later via Put. Because the pool had no closed state, such a late Put re-inserted the connection and armed a fresh expiration timer, resurrecting the pool and leaking the connection (and its manager goroutines) until the timer fired.

This is reachable on shutdown: long-lived streams (e.g. rangefeeds) hold their connection checked out, so Close cannot reach them. When the stream context is later canceled, the connection is handed back via Put and lingers well past the point the pool was closed.

Mark the pool closed under the lock in Close, and have Put close the connection immediately instead of caching it once the pool is closed.

Pool.Close only sees the connections currently idle in the cache.
Connections that are checked out serving an in-flight Invoke or
NewStream live outside the cache and are returned later via Put. Because
the pool had no closed state, such a late Put re-inserted the connection
and armed a fresh expiration timer, resurrecting the pool and leaking the
connection (and its manager goroutines) until the timer fired.

This is reachable on shutdown: long-lived streams (e.g. rangefeeds) hold
their connection checked out, so Close cannot reach them. When the stream
context is later canceled, the connection is handed back via Put and
lingers well past the point the pool was closed.

Mark the pool closed under the lock in Close, and have Put close the
connection immediately instead of caching it once the pool is closed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@suj-krishnan suj-krishnan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants