HLE: wait for in-flight lifecycle callbacks on unregister #3270
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3272"
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?
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T15:21:08Z.
Summary
UnregisterAppStateChangeNotificationandUnregisterAppConstrainedChangeNotificationwithend_title/constrain_then_suspendso unregistering waits until any in-flight invocation of that registration on another thread has returned.CONSTRAINEDandROUTINESupfront inend_title; dispatch each phase from live registrations and re-check membership before every callback so routines unregistered mid-dispatch (including suspend routines unregistered during the constrained phase) are skipped.(id, ThreadId)invocations with an unwind-safe RAII guard so same-thread self-unregistration never deadlocks while another thread concurrently unregistering the same registration still waits until the callback returns, and unregistering unrelated or zero registrations does not block behind other active callbacks.*registrationbefore publishing the entry inNotifications::register.Root Cause
Under Windows Process State Manager (
api-ms-win-core-psm-appnotify-*), returning fromUnregisterAppStateChangeNotificationorUnregisterAppConstrainedChangeNotificationguarantees that the callback is neither executing on another thread nor will be invoked again, allowing the title to destroy the callback'scontextimmediately afterward.Previously,
end_titlecloned both callback vectors before spawning the suspend thread,constrain_then_suspenditerated those stale snapshots without re-checking registration state, and bothUnregister*exports only removed the entry from theVecand returned immediately. This left two use-after-free paths during shutdown/teardown:context.context.Verification
origin/main(63bcca43) before the fix (returned_early=true, saw_destroyed=trueandunregistered sibling constrained callback must not run).cargo test -p victory-hle --locked(155 unit + 2 integration tests passed)cargo test -p victory-hle --all-features --locked(passed)cargo clippy --workspace --all-targets --locked -- -D warnings(passed)cargo clippy --workspace --all-targets --all-features --locked -- -D warnings(passed)cargo test -p xtask --locked policy::tests::repository_passes_policy(passed)Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T15:27:52Z.
Review: APPROVED
Reviewed the diff and verified locally on Windows 11 x64:
Notifications(Mutex+Condvar+ active(id, ThreadId)tracking), writing the registration handle before publishing, waiting for in-flight external callbacks onunregister, and avoiding self-deadlock on reentrant self-unregistration cleanly matches Windows PSM semantics.cargo test -p victory-hle --lib modules::lifecycle:: -- --test-threads=1: 15 passed, 0 failed (includingunregister_waits_for_in_flight_lifecycle_callbacks,unregister_skips_unstarted_sibling_and_suspend_callbacks, andself_unregister_does_not_deadlock_while_other_thread_waits_and_unrelated_returns).cargo clippy -p victory-hle --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T22:52:33Z.
Windows 11,
63bcca4+ this PR:cargo test -p victory-hle: lib 155 passed / 0 failed (unpatched63bcca4here: 152 passed; +3), plus the integration suite (1 passed).cargo clippy -p victory-hle --all-targets -- -D warnings: clean.The three new tests are
unregister_waits_for_in_flight_lifecycle_callbacks,unregister_skips_unstarted_sibling_and_suspend_callbacksandself_unregister_does_not_deadlock_while_other_thread_waits_and_unrelated_returns; none of them hangs here. Synthetic only. AI-assisted.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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.