Skip to content

Madsim v0.8.2#4

Draft
kwannoel wants to merge 6 commits into
kwannoel/v0.8.2from
madsim-v0.8.2
Draft

Madsim v0.8.2#4
kwannoel wants to merge 6 commits into
kwannoel/v0.8.2from
madsim-v0.8.2

Conversation

@kwannoel

@kwannoel kwannoel commented Nov 1, 2024

Copy link
Copy Markdown

Does your PR solve an issue?

DO NOT MERGE.

This PR just displays the patch diffs required for madsim.
We provide a patch of sqlx, v0.8.2

This was created with the following steps:

git checkout madsim-v0.7.4
# rewrite 9 commits -> 4 commits below (no change in diff)
git rebase kwannoel/v0.8.2

Yuhao Su and others added 2 commits July 1, 2026 18:09
Cherry-pick of transact-rs#4289 onto the madsim v0.8.2 branch.

PoolInner::release() published a returned connection (push to the idle
queue + release its semaphore permit, which wakes waiters) before
incrementing num_idle. A concurrent pop_idle could pop that connection
and decrement num_idle while it was still 0, wrapping the usize to
usize::MAX. The maintenance task's `for _ in 0..num_idle()` sweep then
spins ~forever inside a single non-yielding poll, pegging a worker; on
a single-connection pool one of its add_permits handoffs strands the
permit on a waiter parked in the spinning worker's LIFO slot,
permanently wedging the pool (RisingWave meta silent hang,
risingwavelabs/risingwave#24991; upstream report transact-rs#3645).

Three-layer fix, each independently sufficient:
1. release(): increment num_idle before publishing the connection, so
   the counter provably never goes below 0 (subs <= pops <= pushes <=
   adds) and never exceeds max_connections.
2. pop_idle(): saturating decrement, so even a future ordering bug can
   only over-count, never wrap.
3. maintenance sweep: cap iterations at max_connections.

Includes a 12-thread stress test over the real try_acquire/release
paths (fails in <1s with observed=usize::MAX before the fix).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
fix(pool): prevent num_idle underflow that wedges the maintenance task
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