Repository navigation
Fix tryClaim busy-looping on a slot held through a thread-local cache - #310
Open
soerenreichardt wants to merge 1 commit into
Open
soerenreichardt wants to merge 1 commit into
soerenreichardt wants to merge 1 commit into
Conversation
The non-blocking `slowClaim(cache)` used by `tryClaim()` only polls the live-queue when its local `slot` variable is null, but never resets it after a failed `live2claim()`. A slot that another thread has claimed through its thread-local cache stays in the live-queue in the TLR_CLAIMED state. When `tryClaim()` polls such a slot, the CAS fails, the slot is pushed onto the disregard pile, and the loop retries the same slot without polling again. `tryClaim()` therefore does not return until the other thread releases the object, and every iteration allocates a `RefillSlot` that stays reachable from the disregard pile. Under contention this exhausts the heap within seconds, and the next `refill()` floods the live-queue with duplicates of the same slot. Reset `slot` at the end of each iteration, so every attempt polls the live-queue, like the timed `slowClaim(timeout, cache)` already does. The loop then terminates once the live-queue is drained. Co-Authored-By: Claude Code <noreply@anthropic.com>
Owner
|
Created https://codeberg.org/chrisvest/stormpot/issues/21 to track |
This branch has not been deployed
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.
Problem
tryClaim()can fail to return while another thread holds an object it claimed through its thread-local cache. While it spins, it allocates without bound. We hit this in production: a pool of 4 objects shared by 8 threads drove a 30 GB JVM into back-to-back full GCs within seconds.Root cause
BlazePool.slowClaim(BSlotCache)only polls the live-queue when its localslotis null:A slot claimed through the thread-local fast path (
tlrClaim,live2claimTlr) is not removed from the live-queue. It sits there in theTLR_CLAIMEDstate. Each pass of the loop then does the following:live.poll()returns that slot.live2claim()fails, because the state isTLR_CLAIMED, notLIVING.RefillSlot, which stays reachable from the pile.slotis still non-null, so the next pass skips the poll and retries the same slot.The loop only exits once the holder calls
release()and the CAS finally succeeds. Until then,tryClaim()behaves like an unbounded blocking claim that also leaks memory. The nextrefill()then callslive.offeronce per pushed node. The live-queue fills with duplicates of the same slot, and later claims have to drain them.The timed
slowClaim(Timeout, BSlotCache)doesn't have this problem. It reassignsslotfromnewAllocations.pop()orlive.poll(...)at the top of every pass, and it is bounded by the timeout. Soclaim(new Timeout(0, ...))returns null immediately in the same situation, whiletryClaim()hangs.Fix
Set
slot = nullat the end of each pass, so every pass polls the live-queue, matching the timed variant.🤖 Generated with Claude Code