Consistently guard restarts against concurrent auto updates (#21016)

This commit is contained in:
Tommaso Sciortino
2026-03-03 22:18:12 -08:00
committed by GitHub
parent bbcfff5cf1
commit 7e06559db2
10 changed files with 48 additions and 31 deletions

View File

@@ -5,7 +5,11 @@
*/
import { vi } from 'vitest';
import { RELAUNCH_EXIT_CODE, relaunchApp } from './processUtils.js';
import {
RELAUNCH_EXIT_CODE,
relaunchApp,
_resetRelaunchStateForTesting,
} from './processUtils.js';
import * as cleanup from './cleanup.js';
import * as handleAutoUpdate from './handleAutoUpdate.js';
@@ -19,6 +23,10 @@ describe('processUtils', () => {
.mockReturnValue(undefined as never);
const runExitCleanup = vi.spyOn(cleanup, 'runExitCleanup');
beforeEach(() => {
_resetRelaunchStateForTesting();
});
afterEach(() => vi.clearAllMocks());
it('should wait for updates, run cleanup, and exit with the relaunch code', async () => {

View File

@@ -15,7 +15,16 @@ export const RELAUNCH_EXIT_CODE = 199;
/**
* Exits the process with a special code to signal that the parent process should relaunch it.
*/
let isRelaunching = false;
/** @internal only for testing */
export function _resetRelaunchStateForTesting(): void {
isRelaunching = false;
}
export async function relaunchApp(): Promise<void> {
if (isRelaunching) return;
isRelaunching = true;
await waitForUpdateCompletion();
await runExitCleanup();
process.exit(RELAUNCH_EXIT_CODE);