fix(das): deep-copy worker failed map in getState to avoid stats race#5057
Open
neyy91 wants to merge 1 commit into
Open
fix(das): deep-copy worker failed map in getState to avoid stats race#5057neyy91 wants to merge 1 commit into
neyy91 wants to merge 1 commit into
Conversation
getState returned workerState by value, but the embedded result's `failed` map was shared by reference with the running worker. The coordinator's unsafeStats path iterates that map (via getState) without holding the worker lock, while the worker keeps writing to it under the lock during sampling. Concurrent map iteration and map write is a fatal runtime error, so polling SamplingStats or the periodic checkpoint could crash a node that is sampling. Deep-copy the map under the lock so each snapshot is independent. Adds a regression test reproducing the concurrent read/write (fails under -race before the fix).
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.
Overview
worker.getState()returnedworkerStateby value, but the embeddedresult.failedmap was shared by reference with the running worker. The coordinator'sunsafeStatsiterates that map (viagetState) without holding the worker lock, while the worker keeps writing to it under the lock during sampling. Concurrent map iteration and map write is a fatal runtime error, so pollingSamplingStatsor the periodic background checkpoint could crash a sampling node.Fix: deep-copy the map under the lock so each snapshot is independent. Pausing the coordinator (the existing
stats()mechanism) does not pause workers, so the snapshot must not alias worker-owned state.Adds a regression test reproducing the concurrent read/write; it fails under
-racebefore the fix.Closes #5056