fix(desktop): clear swap flow timer in finally + drop duplicate env-state removal

- move clearTimeout(flowTimeoutHandle) into the finally block so it fires
  on success, error, and timeout — previously the error path left a live
  180s timer that would reject an unreferenced promise (unhandled rejection)
- remove the second removeEnvironmentState call after welcome; the first
  call right after the IPC swap already wipes the old environment state
  and nothing recreates state under the old env id during reauth/welcome
This commit is contained in:
Josh Gratton committed 2026-05-16 11:38:36 -04:00
1 parent 3b9f86cd4a
commit 80eddbbef9
1 file changed
+3 -6
@@ -2433,16 +2433,10 @@ export function ConnectionsSettings() {
window.setTimeout(resolve, 45_000);
}),
]);
if (aborted) return;
if (previousPrimaryEnvId) {
useStore.getState().removeEnvironmentState(previousPrimaryEnvId);
}
};
try {
await suppressReconnect(() => Promise.race([runSwap(), flowTimeout]));
if (flowTimeoutHandle !== null) window.clearTimeout(flowTimeoutHandle);
setPendingDesktopWslSelection(null);
toastManager.add({
@@ -2469,6 +2463,9 @@ export function ConnectionsSettings() {
.then((state) => setDesktopWslState(state))
.catch(() => undefined);
} finally {
// Clear the global timer on every path so it can't fire after the flow
// has settled and reject an unreferenced promise.
if (flowTimeoutHandle !== null) window.clearTimeout(flowTimeoutHandle);
unsubscribeWelcome();
setIsUpdatingWslBackend(false);
setDesktopWslChangeStage(null);