fix(restart): the self-relaunch waits for its parent's mutex

A database switch relaunches OpsLog, and the child regularly won the
race against the old instance's teardown — so following the app's own
instructions produced 'OpsLog is already running'. The relaunch now
passes --relaunch, which gets the same 20-second mutex patience the
post-update restart has always had. Opens the 0.27.6 block.
This commit is contained in:
2026-08-31 14:19:30 +02:00
parent 8790b98766
commit 68f0d68980
3 changed files with 23 additions and 7 deletions
+10 -6
View File
@@ -48,14 +48,14 @@ func hasFlag(args []string, flag string) bool {
}
// acquireInstance grabs the single-instance mutex. On a normal launch it's a plain
// try (fail → another OpsLog is running, so exit). On a --post-update relaunch the
// previous instance may still be shutting down and holding the mutex, so retry for
// a few seconds until it frees.
func acquireInstance(postUpdate bool) bool {
// try (fail → another OpsLog is running, so exit). On a --post-update or
// --relaunch start the previous instance may still be shutting down and holding
// the mutex, so retry for a few seconds until it frees.
func acquireInstance(wait bool) bool {
if acquireSingleInstance() {
return true
}
if !postUpdate {
if !wait {
return false
}
deadline := time.Now().Add(20 * time.Second)
@@ -90,7 +90,11 @@ func main() {
// to free instead of bailing out. Then clear the old exe it left behind.
bootLogLaunch()
postUpdate := hasFlag(os.Args[1:], "--post-update")
if !acquireInstance(postUpdate) {
// A self-relaunch (database switch) races its own parent: the new process
// regularly wins the start against the old one's teardown, and the operator
// got "OpsLog is already running" for following instructions. Same patience
// as post-update.
if !acquireInstance(postUpdate || hasFlag(os.Args[1:], "--relaunch")) {
// SAID, not merely done. This exit is correct — a second instance would
// fight the first over the rig — but it happened in total silence: no
// window, no data folder, no log, which is indistinguishable from a