HLE/gameinput: write callback token before registration and order blocking enumeration #485
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!485
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-485"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@AscilCH on GitHub · 2026-11-25 01:23 UTC · original
AscilCH:fix/hle-gameinput-callback-registration-race→main· +156 −14 · 1 files · 1 commits · openProblem
Two concurrency races in
register_device(crates/victory-hle/src/modules/gameinput.rs):*outreceives the registration token:register_devicepushedregistrationintostate.callbacksand releasedhub.state()before writing*out = registration.token. A concurrentpoll()thread could invoke the callback before*outwas written, racing with the title's token slot.poll():enumeration != 0 && enumeration != ASYNC_ENUMERATION),register_deviceaddedregistrationtostate.callbacks, releasedhub.state(), and then delivered the initialCONNECTEDsnapshot. A concurrentpoll()noticing a disconnect in that window could deliverDISCONNECTEDconcurrently with or ahead of the initialCONNECTEDcallback, inverting the device state seen by the title.Fix
*out = registration.tokenbefore lockinghub.state()and insertingregistrationintostate.callbacks.State::enumeratingand queue any concurrentpoll()events for those tokens intoState::deferred(discarded onforget()).State::deferredfor the token on the registering thread after initial enumeration finishes, clearingenumeratingonly once no deferred events remain (or the callback was unregistered), without ever holdinghub.state()across user callback calls.blocking_enumeration_writes_token_first_and_orders_concurrent_poll.Verification
cargo test -p victory-hle --locked gameinput::tests: 7 passed, 0 failedcargo xtask policy: 169 files okcargo clippy -p victory-hle --all-targets --locked -- -D warnings: cleancargo clippy -p victory-hle --all-targets --all-features --locked -- -D warnings: clean(AI-assisted; synthetic unit tests only, no game data.)
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.