Skip to content

Fix pool slot leak on cancelled checkout that wedges the pool (#20) - #22

Merged
solidcitizen merged 1 commit into
mainfrom
fix/issue-20-slot-reservation-leak
Sep 18, 2026
Merged

solidcitizen merged 1 commit into
mainfrom
fix/issue-20-slot-reservation-leak

Conversation

@solidcitizen

Copy link
Copy Markdown
Owner

Fixes #20. Hotfix release 1.0.4 (#20 only; #15/#14 follow as 1.0.5).

The defect

In pool mode, Pool::checkout reserves a slot (bucket.total += 1) before awaiting create_connection. That runs inside the per-connection handshake timeout, so when the upstream accepts the socket but is slow to answer the startup, the future is dropped mid-await and neither the Ok nor Err arm runs — the reserved slot is never released, and the PoolLease guard doesn't exist yet. Each cancelled checkout leaks one phantom slot; once total reaches pool_size with no real connections, every later checkout fails pool checkout timeout: all connections in use — a permanent wedge cleared only by restart.

Pre-existing since pooling (0.3); present in 1.0.0–1.0.3. Not a regression from #11 — 1.0.2 (0ce3be6) wedges identically under the same probe.

The fix

An RAII SlotReservation guard holds the reserved slot and decrements total on every exit — Err return or cancellation — and is disarmed only once the connection exists and owns the slot. Mirrors the PoolLease guard from #11.

Verification

  • cargo fmt --check, cargo clippy -- -D warnings, cargo test (94 unit tests) — green.
  • ./tests/run.sh 52/52, including new Suite 9: a black-hole upstream (tests/blackhole.mjs) that forces every create_connection to be cancelled, asserting the bucket total returns to 0 and the pool is not wedged.
  • Red-then-green on Suite 9's exact config: 1.0.2/1.0.3 pin total at pool_size and report "all connections in use"; fixed returns total to 0 and a fresh checkout still attempts a real connect.
  • NexusPlus contract suite passes against the RC binary; hand-off integrity (Protocol desync (unexpected CommandComplete) under concurrent tenant-context checkouts — not app-side client sharing #11) holds on 1.0.4.

Bumps version to 1.0.4.

Pool mode: `Pool::checkout` reserves a slot (`bucket.total += 1`) under the
lock, then awaits `create_connection`. It runs inside the per-connection
handshake timeout (`tokio::time::timeout`), so when the upstream accepts the
TCP connection but is slow or unresponsive to the startup, that await can be
dropped mid-flight. Neither the Ok nor the Err arm then runs, and the
`PoolLease` guard is only created after checkout returns, so the reserved slot
was never decremented. Each cancelled checkout leaked one phantom slot; once
`total` reached `pool_size` with no real connections, every later checkout
found the bucket "full" with nothing to hand out and failed
`pool checkout timeout: all connections in use` — a permanent wedge cleared
only by restart.

Pre-existing since pooling (0.3); present in 1.0.0–1.0.3. Not a regression
from the #11 work — 1.0.2 (0ce3be6) wedges identically under the same probe.

Fix: hold the reserved slot in an RAII guard (`SlotReservation`) that
decrements `total` on every drop — Err return or cancellation — and is
disarmed only once the connection exists and its slot is owned by the returned
conn. Mirrors the `PoolLease` guard from #11.

Regression coverage (Suite 9, tests/run.sh): a black-hole upstream
(tests/blackhole.mjs) that accepts TCP but never responds forces every
create_connection to be cancelled; the test asserts the bucket total returns
to 0 and the pool is not wedged. Verified red on 1.0.2/1.0.3 (total pinned at
pool_size, "all connections in use") and green after (total 0, fresh checkout
still attempts a real connect). Deterministic black-hole probe confirms the
fix holds `total` at 0 across repeated cancellations.

Bump version to 1.0.4.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-18T08:16:15.935151Z 9af4ce2 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@solidcitizen
solidcitizen merged commit 603b0f6 into main Sep 18, 2026
3 checks passed
@solidcitizen
solidcitizen deleted the fix/issue-20-slot-reservation-leak branch September 18, 2026 08:16
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.

Pool mode: cancelled checkout leaks a reserved slot; enough leaks permanently wedge the pool (pre-existing)

1 participant