Madsim v0.8.2#4
Draft
kwannoel wants to merge 6 commits into
Draft
Conversation
5869213 to
3efe6d0
Compare
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: