fix(update): relaunch the new version instead of the old running process - #69
Merged
Merged
Conversation
Clicking "Restart now" after an update kept running the previous version. Two compounding causes, neither addressed by the earlier relaunch-path fix: - RestartApplication never set the `quitting` flag, so `beforeClose` intercepted `runtime.Quit` and merely hid the window whenever "Minimize to tray" was enabled. The old process lingered in the tray running the previous version and never released the single-instance lock. Set the flag before quitting, mirroring QuitApp. - Even when the old process did quit, the freshly spawned binary raced its shutdown: while the old instance still held the `com.plexcord.app` single-instance lock, the new one was treated as a second instance, restored the old window, and exited. The new version never ran. The relaunched child now receives the old PID via PLEXCORD_RELAUNCH_PID and waits (bounded) for that process to exit before wails.Run acquires the single-instance lock, so the updated binary starts as the primary instance. Process liveness is checked per-platform (WaitForSingleObject on Windows, signal 0 on Unix). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CTxwvdhzd1rVPZt98Acf9A
- Check the os.Unsetenv error in waitForPreviousInstanceExit (errcheck check-blank). - Use exec.CommandContext in the relaunch tests (noctx). - Guard pid and close the process handle in the Windows liveness check so windows-tagged builds also lint clean (gosec G115, errcheck). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CTxwvdhzd1rVPZt98Acf9A
DamienBattistella
marked this pull request as ready for review
July 10, 2026 16:41
|
🎉 This PR is included in version 1.10.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Clicking "Restart now" / "Redémarrer maintenant" after an update finished downloading kept running the previous version (e.g. it stayed on
v1.9.0instead of switching tov1.10.0). The earlier fix (#67) corrected which binary path the relaunch targets on disk, but two remaining bugs kept the old process alive:RestartApplicationnever set thequittingflag.QuitAppsetsa.quitting.Store(true)beforeruntime.Quitspecifically sobeforeClosedoesn't intercept the quit.RestartApplicationomitted this, so when "Minimize to tray" was enabled,beforeCloseran withquitting == falseand returnedtrue(prevent) → the old process merely hid its window instead of quitting, lingering in the tray on the previous version and never releasing the single-instance lock.Single-instance-lock race.
cmd.Start()launches the new binary, thenruntime.Quitbegins a shutdown that takes time (disconnect Discord, stop tray, …). During that window the old process still holds thecom.plexcord.appsingle-instance lock, so the freshly-launched new binary is treated as a second instance — it callsonSecondInstanceLaunch(restores the old window) and exits. The new version never runs.Fix
a.quitting.Store(true)beforeruntime.QuitinRestartApplication(mirrorsQuitApp), so the old process actually terminates regardless of the "Minimize to tray" setting.PLEXCORD_RELAUNCH_PID. Inmain(), beforewails.Runacquires the single-instance lock, the child waits (bounded to 15s) for that PID to exit and for the OS to release the lock. The updated binary then starts as the primary instance.WaitForSingleObjecton Windows (relaunch_windows.go), signal0on Unix (relaunch_unix.go).Type of Change
Related Issues
Fixes the reported issue where the app restarts the current process rather than the freshly downloaded new version.
Testing
Added
relaunch_test.gocoveringprocessExists(self alive, reaped-child dead) andwaitForPreviousInstanceExit(no-op without the env marker; returns promptly and clears the env when the predecessor is already gone). Verifiedgo build,go vet, and the fullgo test ./...suite pass for bothlinux/amd64andwindows/amd64.Checklist
Additional Notes
Both fixes are needed together: fix (1) makes the old process actually exit, and fix (2) ensures the new binary doesn't bail out as a "second instance" during the old process's shutdown window.
🤖 Generated with Claude Code
Generated by Claude Code