Skip to content

Commit 017f1d6

Browse files
committed
Stop the new backend before rolling back a failed WSL toggle
Two follow-ups from the latest review pass: - main.ts WSL_SET_CONFIG_CHANNEL: when startBackend() succeeded but the readiness wait then failed (e.g. a slow first WSL boot exceeding the 60s timeout), the spawned child kept running under the new mode while the on-disk config and renderer state silently reverted, leaving runtime and persisted state inconsistent until the next backend exit. Stop the new-mode child explicitly, save the previous config, and relaunch under it; if the rollback start also fails, fall back to the exponential-backoff restart so the loop keeps trying. - wsl.ts runWslShellScript: the stdin "error" handler and the catch around stdin.write/end called settle() without first killing the spawned wsl.exe child, so a stdin failure after spawn left the child running with no termination path (the timeout that would have killed it is cleared by settle()). Kill the child before settle() in those paths to match the timeout-handler shape.
1 parent f8bdfa8 commit 017f1d6

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

apps/desktop/src/main.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,12 +2016,17 @@ function registerIpcHandlers(): void {
20162016
await waitForBackendWindowReady(backendHttpUrl);
20172017
return true;
20182018
} catch (error) {
2019-
// Roll back so the on-disk config matches the renderer's view; the
2020-
// exponential-backoff restart will relaunch under the previous
2021-
// configuration. Without this, the renderer's error toast leaves the
2022-
// UI showing the old toggle while the next app launch silently honors
2023-
// the never-confirmed configuration.
2019+
// Stop whatever started under the new config (it may still be alive
2020+
// if startBackend succeeded but readiness then timed out), revert
2021+
// the on-disk config, and relaunch under the previous configuration.
2022+
// Without the explicit stop, runtime and persisted state can diverge
2023+
// until the new-mode child exits on its own.
2024+
await stopBackendAndWaitForExit().catch(() => {});
20242025
saveWslConfig(STATE_DIR, previousConfig);
2026+
const restarted = await startBackend().catch(() => false);
2027+
if (!restarted) {
2028+
scheduleBackendRestart("WSL config rollback");
2029+
}
20252030
throw error;
20262031
}
20272032
};

apps/desktop/src/wsl.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,19 @@ function runWslShell(
235235

236236
const stdin = child.stdin;
237237
if (stdin) {
238-
stdin.once("error", (error) => settle(127, `\n${error.message}`));
238+
stdin.once("error", (error) => {
239+
child.kill();
240+
settle(127, `\n${error.message}`);
241+
});
239242
try {
240243
stdin.write(bashScript);
241244
stdin.end();
242245
} catch (error) {
246+
child.kill();
243247
settle(127, `\n${error instanceof Error ? error.message : String(error)}`);
244248
}
245249
} else {
250+
child.kill();
246251
settle(127, "\n[stdin pipe unavailable]");
247252
}
248253
});

0 commit comments

Comments
 (0)