Skip to content

Clear checkout state when shutdown cleanup raises - #220

Open
OskarEichler wants to merge 1 commit into
mperham:mainfrom
OskarEichler:codex/clear-checkout-error-upstream
Open

Clear checkout state when shutdown cleanup raises#220
OskarEichler wants to merge 1 commit into
mperham:mainfrom
OskarEichler:codex/clear-checkout-error-upstream

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

Always clear the final checked-out connection reference and nesting count, including when a shutdown cleanup callback raises during checkin.

The callback exception still propagates. The change prevents a subsequent checkout from bypassing the closed pool and returning the stale connection left in the caller's local state.

Reproduction

require 'connection_pool'
pool = ConnectionPool.new(size: 1) { Object.new }
pool.checkout
pool.shutdown { raise 'close failed' }
begin
  pool.checkin
rescue RuntimeError
end
pool.checkout

Before: the last call returns the old connection, despite shutdown.
After: it raises ConnectionPool::PoolShuttingDownError.

Verification

  • Ruby 4.0.6: existing suite passes with the release-based patch, 86 runs / 187 assertions / zero failures or errors.
  • Focused ordinary and forced final-checkin cases confirm cleanup error propagation and rejection of subsequent checkout.
  • Existing targeted StandardRB, Ruby syntax and git whitespace checks pass.
  • This PR contains only the cleanup correction on main. The consumer patch is based on installed v3.0.2.

Limitations and breaking changes

  • Used an external verification Gemfile to add Minitest 6's extracted minitest-mock support (also present in current upstream). The unmodified release setup initially had four missing-stub errors. No test/Gemfile/gemspec changes included.
  • No new tests under the consumer's no-new-tests policy; existing tests and the focused reproduction were run.
  • No JRuby/TruffleRuby/Linux runtime checks were run locally.
  • Breaking changes: none intended. Shutdown callback exceptions still propagate; subsequent checkout now honors shutdown. Nested checkin and discarded-connection cleanup retain their existing behavior.

Prepared with Codex assistance.

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.

1 participant