Skip to content

fix: let the update helper exit, reopen the app and clean up after itself - #40

Merged
CodySimonds65 merged 3 commits into
mainfrom
fix/update-helper-hang
Oct 6, 2026
Merged

CodySimonds65 merged 3 commits into
mainfrom
fix/update-helper-hang

Conversation

@CodySimonds65

Copy link
Copy Markdown
Owner

After an update the app never reopened, and the temporary update helper stayed running forever. Each update leaked one helper process, its ~87 MB exe, the downloaded update and a folder of extracted native libraries in the temp folder.

Root cause

The helper was not waiting on the parent process or a file lock. It was stuck on a Windows security prompt nobody could see:

  1. An exe first downloaded with a browser carries a Zone.Identifier stream (the download mark).
  2. ReplaceTargetFile swaps the exe with File.Replace, which keeps the old file's alternate data streams, so every updated exe keeps the mark.
  3. TryLaunch reopened the app with UseShellExecute = true, so the shell raised "Open File - Security Warning" for the unsigned, marked exe.
  4. The helper is started with CreateNoWindow and WindowStyle.Hidden, so that dialog is created hidden and the helper's main thread blocks on it forever.

Confirmed on a machine with 20 leaked helpers: the main thread of each was inside ShellExecuteExW → CheckSmartScreen → DialogBox, and each owned a hidden dialog with that title.

Fix

  • Relaunch without the shell. TryLaunch now uses UseShellExecute = false, which starts the exe directly and skips the shell's zone check, so there is no prompt to block on.
  • Clear finished helpers on the next start. A helper cannot delete its own running exe, so one exe and one extraction folder were left behind per update even when nothing hung. UpdateInstaller.DeleteStaleHelpers removes them when the app starts its update check. A helper that is still running keeps its exe locked, and its extraction folder is kept with it.

Tests

  • HelperExitsAfterReplacingAnExeThatCarriesTheMarkOfTheWeb runs the real built exe in --apply-update mode against a target marked ZoneId=3. It timed out at 30 s before the fix and passes after it.
  • DeleteStaleHelpersRemovesFinishedHelpersAndLeavesRunningOnesAndOtherFiles checks the cleanup takes finished helpers and orphaned extraction folders, and leaves a locked helper, its folder and unrelated files alone.

dotnet test src/FourFoldAccountManager.Desktop.Tests: 33 passed. dotnet test src/FourFoldAccountManager.Core.Tests: 310 passed.

Also checked by hand with a single-file build published the same way as the release workflow, marked ZoneId=3 and versioned below the latest release: it downloaded the update, the helper exited within a second, the app reopened visibly with no prompt, and the download was deleted. A second build then removed a planted stale helper exe and extraction folder from the temp folder on startup.

Not changed

  • The download mark is left on the exe. Removing it after the checksum-verified replace would also stop Explorer prompting on a double-click, but that is a security decision for a separate change.
  • Helpers already stuck from earlier versions are not stopped by the app. They end at sign-out or restart, and their files are then cleared on the next start.
  • The hang test can only fail on a machine where Windows prompts for marked files, which is the default. Where policy turns that prompt off it passes either way.

Note on rollout

Installed copies up to v1.1.30 still have the bug in their own helper, so their update to the release containing this fix will leave one last stuck helper and not reopen. Updates from that release onward behave correctly.

Merging publishes a client release, since this touches src/.

The helper relaunches the replaced exe through the shell. When the exe still carries its Zone.Identifier stream, Windows raises Open File - Security Warning inside the hidden helper, so it never exits.
File.Replace keeps the old exe's Zone.Identifier stream, so a shell relaunch prompted in the hidden helper and blocked it forever. The app never reopened and the helper, its download and its extraction folder were left behind on every update.
A helper cannot delete its own running exe, so every update left the helper exe and its extracted native libraries in the temp folder. The app now removes them when it starts, skipping any helper that is still running.
@CodySimonds65
CodySimonds65 merged commit 86650e9 into main Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant