Fix native wait lifetime during asynchronous fence completion - #938
Open
andrewsil1 wants to merge 2 commits into
Open
andrewsil1 wants to merge 2 commits into
andrewsil1 wants to merge 2 commits into
Conversation
andrewsil1
marked this pull request as ready for review
September 30, 2026 17:50
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.
Closes #936
Description
Asynchronous fence completion currently discards the native wait registration handle and frees its event and callback context without unregistering the wait. Retain the registration and explicitly cancel it before releasing those resources.
WT_EXECUTEONLYONCEand coordinate handle publication with callback completion using an atomic handshake. Either ordering assigns cleanup to exactly one participant.UnregisterWaitExfrom the callback, acceptingERROR_IO_PENDINGthere. When the callback arrives before publication, unregister and join it from the publishing thread instead.No public API changes.
Validation
Passed on Windows with .NET SDK 10.0.401, against upstream
40dbe40de0b1eafb570e2af43f78bcdbffdcc00a:The full internal test project passed: 138 tests, zero failures or skips. The new GPU-independent test covers both publication orderings, duplicate arrival rejection, 10,000 concurrent publication races, cancellation-result classification, 2,000 native wait cycles with a handle-growth bound, and last-error capture. The native probe uses the production publication helper and a small test callback; it does not inject failures into the D3D12 completion path.
The complete repository test suite was not run. Device removal, allocation failures, and actual native unregistration failures were not injected. The change does not redefine the broader device-loss contract or attribute a GPU failure to this defect.
Additional context
RegisterWaitForSingleObject requires explicit cancellation even for one-shot waits. UnregisterWaitEx documents the callback deadlock constraint and pending-callback return behavior used here.