fix(updates): the swap waits for a new launcher still held after its self-check #228

Merged
HumanBean merged 1 commit from HumanBean/LongshotLauncher:fix/self-update-held into main 2026-11-21 19:14:29 +00:00
Owner

The launcher could not update itself on Windows: the new launcher is still held for a moment after its --self-check has ended, so the rename that puts it in place fails with "being used by another process", and the player sees only that error.

Fixes #223

Summary

  • Cause. The --self-check child prints its version and returns at the top of Main; it starts nothing and holds nothing once it has ended, and the launcher closes all its own handles on the .new before starting it. So whatever holds it 500 ms later is another process opening a program it has just seen run, most likely an antivirus scan (Defender), and it lets go soon after: at the next start, Recover deletes the same .new with no trouble. The log shows two failures: Swap's move (logged without a path: File.Move's message), then the finally's File.Delete(staged), whose message, with the path, replaced the first one and is what Home showed.
  • SelfUpdate.WhileHeld. On Windows, the move of the new launcher into place is tried again while it fails as held (sharing violation, lock violation, or the access denied that File.Move throws as an IOException), waiting 0.1 s, then 0.25, 0.5, 1 and 2 s, about 10 s in all. Any other failure is thrown at once, and the one before is still put back when it times out.
  • Off the window's thread. UpdateLauncherAsync runs the swap in Task.Run, so these waits don't freeze the window.
  • SelfUpdate.Discard. The staged file's cleanup no longer throws: when it cannot be deleted yet it is logged and left for the next start's Recover, and the update's own error is the one shown.

Launchers up to v1.1.0 run their own swap code, so this helps updates from the release that has it. A v1.0.0 or v1.1.0 launcher that fails can try again, or the player can unpack the new portable zip over it.

Testing

  • python -I tests/test_launcher_core.py: 2608 checks passed. The new checks give WhileHeld Windows' HRESULTs as File.Move throws them: it moves once the file is let go, gives up after the waits with the error, and throws other errors at once. They also check that a Windows swap with nothing held does not wait, and that Discard leaves a file it cannot delete without throwing.
  • LAUNCHER=$PWD python -I ../Tooling/tests/test_release.py: 3 failures (test_the_bump, test_the_next_stable, test_check_tag_against_the_published_releases), the same 3 on main without this change, as they read this repository's tags. This change touches nothing of the release format.
  • dotnet build App: no warnings.
  • Not run on Windows: this PC is Linux, so the real lock (an antivirus holding the file) was not reproduced.

🤖 Generated with Claude Code

The launcher could not update itself on Windows: the new launcher is still held for a moment after its `--self-check` has ended, so the rename that puts it in place fails with "being used by another process", and the player sees only that error. Fixes #223 ## Summary - **Cause.** The `--self-check` child prints its version and returns at the top of `Main`; it starts nothing and holds nothing once it has ended, and the launcher closes all its own handles on the `.new` before starting it. So whatever holds it 500 ms later is another process opening a program it has just seen run, most likely an antivirus scan (Defender), and it lets go soon after: at the next start, `Recover` deletes the same `.new` with no trouble. The log shows two failures: `Swap`'s move (logged without a path: `File.Move`'s message), then the `finally`'s `File.Delete(staged)`, whose message, with the path, replaced the first one and is what Home showed. - **`SelfUpdate.WhileHeld`.** On Windows, the move of the new launcher into place is tried again while it fails as held (sharing violation, lock violation, or the access denied that `File.Move` throws as an `IOException`), waiting 0.1 s, then 0.25, 0.5, 1 and 2 s, about 10 s in all. Any other failure is thrown at once, and the one before is still put back when it times out. - **Off the window's thread.** `UpdateLauncherAsync` runs the swap in `Task.Run`, so these waits don't freeze the window. - **`SelfUpdate.Discard`.** The staged file's cleanup no longer throws: when it cannot be deleted yet it is logged and left for the next start's `Recover`, and the update's own error is the one shown. Launchers up to v1.1.0 run their own swap code, so this helps updates *from* the release that has it. A v1.0.0 or v1.1.0 launcher that fails can try again, or the player can unpack the new portable zip over it. ## Testing - `python -I tests/test_launcher_core.py`: 2608 checks passed. The new checks give `WhileHeld` Windows' HRESULTs as `File.Move` throws them: it moves once the file is let go, gives up after the waits with the error, and throws other errors at once. They also check that a Windows swap with nothing held does not wait, and that `Discard` leaves a file it cannot delete without throwing. - `LAUNCHER=$PWD python -I ../Tooling/tests/test_release.py`: 3 failures (`test_the_bump`, `test_the_next_stable`, `test_check_tag_against_the_published_releases`), the same 3 on `main` without this change, as they read this repository's tags. This change touches nothing of the release format. - `dotnet build App`: no warnings. - Not run on Windows: this PC is Linux, so the real lock (an antivirus holding the file) was not reproduced. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
fix(updates): the swap waits for a new launcher still held after its self-check
All checks were successful
CI / Compile and test (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 16s
6fee80006f
On Windows the new launcher is often held a moment after its --self-check
has ended (an antivirus scanning a program it has just seen run), and the
rename into place failed with a sharing violation. The move is tried again
for about 10 seconds, off the window's thread. The staged file's cleanup no
longer throws: it hid the reason, and the next start removes the file.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
HumanBean deleted branch fix/self-update-held 2026-11-21 19:14:31 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/LongshotLauncher!228
No description provided.