diff --git a/packaging/windows/installer.nsh b/packaging/windows/installer.nsh index 898bb6b..103b72d 100644 --- a/packaging/windows/installer.nsh +++ b/packaging/windows/installer.nsh @@ -345,20 +345,31 @@ Function restartFarmControlAfterUpdate ; builds can keep bun/renderer processes alive after the launcher exits. System::Call 'kernel32::OpenProcess(i 0x00100000, i 0, i $UpdateParentPid) p .r0' ${If} $0 != 0 - ; Allow two minutes for a graceful CEF shutdown. - System::Call 'kernel32::WaitForSingleObject(p r0, i 120000) i .r1' - System::Call 'kernel32::CloseHandle(p r0)' - + ; Allow two seconds for a graceful exit, then terminate the process tree. + System::Call 'kernel32::WaitForSingleObject(p r0, i 2000) i .r1' ${If} $1 == 258 - !insertmacro progressStatus "Farm Control is taking too long to close; forcing shutdown..." + !insertmacro progressStatus "Stopping Farm Control..." DetailPrint "Farm Control process $UpdateParentPid did not exit; terminating its process tree..." ExecWait 'taskkill /F /T /PID $UpdateParentPid' $R0 + + ; Verify that taskkill actually terminated the process before swapping. + System::Call 'kernel32::WaitForSingleObject(p r0, i 10000) i .r1' + ${EndIf} + + System::Call 'kernel32::CloseHandle(p r0)' + ${If} $1 != 0 + !insertmacro progressFailure "Could not stop the running Farm Control process." + Abort ${EndIf} ${EndIf} ${Else} ; Compatibility fallback for manually launched older installers. + Sleep 2000 + !insertmacro quitFarmControl + + ; Confirm both known launcher names have stopped before continuing. StrCpy $R7 0 - restart_wait_loop: + restart_verify_loop: ExecWait 'cmd.exe /c tasklist /FI "IMAGENAME eq FarmControl.exe" 2>nul | find /I "FarmControl.exe"' $R0 ${If} $R0 != 0 ExecWait 'cmd.exe /c tasklist /FI "IMAGENAME eq launcher.exe" 2>nul | find /I "launcher.exe"' $R0 @@ -368,13 +379,13 @@ Function restartFarmControlAfterUpdate ${EndIf} IntOp $R7 $R7 + 1 - ${If} $R7 < 80 - Sleep 1500 - Goto restart_wait_loop + ${If} $R7 < 20 + Sleep 500 + Goto restart_verify_loop ${EndIf} - !insertmacro progressStatus "Farm Control is taking too long to close; forcing shutdown..." - !insertmacro quitFarmControl + !insertmacro progressFailure "Could not stop the running Farm Control process." + Abort ${EndIf} restart_wait_done: