AsyncLib: Port data race fix from GDK w/ AsyncBlock written after AsyncGetStatus. - #1008
Open
ernadeau wants to merge 1 commit into
Open
AsyncLib: Port data race fix from GDK w/ AsyncBlock written after AsyncGetStatus.#1008ernadeau wants to merge 1 commit into
ernadeau wants to merge 1 commit into
Conversation
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.
[PORT OF A FIX MADE TO 2604 GDK]
Why is this change being made?
XAsyncComplete published the block's "dead" signature (0 / ASYNC_BLOCK_RESULT_SIG ) from ExtractState while still holding the spin-lock and with pending writes. DoLock 's unlocked fast path skips locking when signature != ASYNC_BLOCK_SIG , so a concurrent XAsyncGetStatus(wait=true) could see terminal status + null state, return, and let the app free the block before the completer's final lock.clear() landed - a use-after-free confirmed by a live repro (write to the freed user block, asynclib lock.clear() at completion).
What changed?
Made AsyncBlockInternal::signature a std::atomic<uint32_t> and deferred the dead-signature publish: the guard destructor now stores it (release) as its final write, after both lock.clear() s, and readers acquire-load it. DoLock gained a retry loop that, on a locked block whose state is already extracted but whose dead signature isn't yet published, waits for that store before returning null - closing the race. Added regression test VerifyNoWriteAfterGetStatusRace (20k iterations, byte-identical block); full suite 90/90.
How was the change tested?