Repository navigation
fix(single-instance): handle Windows startup race and ensure secondary instance exits - #3704
Conversation
|
Requesting Tony's review since he also reviewed #3495 |
There was a problem hiding this comment.
This should close #3495, let's add it to the PR description.
I don't really like how both PRs are done through agents (without putting in effort even editing the PR descriptions and comment responses) and I honestly don't want to accept either of them but well, a new era here we are 🤷♂️
Package Changes Through 0b039d2There are 1 changes which include single-instance with patch Planned Package VersionsThe following package releases are the planned based on the context of changes in this pull request.
Add another change file through the GitHub UI by following this link. Read about change files or the docs at github.com/jbolda/covector |
|
Fair point on the verbose description formatting Tony, got a bit lazy drafting the writeup! 😅 Cleaned up the polling loop into a single pass and dropped the redundant CloseHandle as requested. Also added Closes #3495 to the description. Appreciate the review! |
Legend-Master
left a comment
There was a problem hiding this comment.
Thanks
Also you'll need to sign your commits for me to merge this
https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits
262a38c to
0b039d2
Compare
|
Done! Rebased onto latest v2 and pushed with verified signed commits. Ready for merge! @Legend-Master |
Fixes #3587
Closes #3495
Description
On Windows, when two instances are launched in rapid succession (e.g. fast shortcut double-clicks, concurrent autostarts), the primary instance publishes its named mutex (
CreateMutexW) before creating its event target window (create_event_target_window).In the secondary instance:
CreateMutexWdetectsERROR_ALREADY_EXISTS.FindWindowWis called immediately and returnsnullbecause the primary instance's event target window has not yet been registered.if !hwnd.is_null()with noelsebranch. Consequently, whenFindWindowWmissed the startup window, the secondary instance fell through and booted completely, violating the single-instance contract and causing severe concurrency issues (such as SQLitedatabase is lockederrors).Solution
FindWindowWso that secondary instances launched within the startup window can reliably discover the primary window and forward their CLI arguments / deep-links.ERROR_ALREADY_EXISTSis observed, the secondary instance executesapp.cleanup_before_exit()and terminates withstd::process::exit(0).