Fix WSL picker and backend restart edge cases
This commit is contained in:
1 parent
d729b00b01
commit
c61ea48549
7 files changed
+65
-27
No files matched your search
@@ -235,10 +235,10 @@ const scopedProgram = Effect.scoped(
|
||||
yield* Effect.annotateCurrentSpan({ scope: "desktop", runId });
|
||||
|
||||
const shutdown = yield* DesktopLifecycle.DesktopShutdown;
|
||||
const pool = yield* DesktopBackendPool.DesktopBackendPool;
|
||||
|
||||
yield* Effect.addFinalizer(() =>
|
||||
Effect.gen(function* () {
|
||||
const pool = yield* DesktopBackendPool.DesktopBackendPool;
|
||||
// Stop every backend in the pool, not just the primary. The
|
||||
// electronApp.quit() path can race ahead of the layer-scope
|
||||
// cascade, so leaving the WSL instance for its parent scope
|
||||
|
||||
@@ -23,7 +23,11 @@ import * as ElectronTheme from "../../electron/ElectronTheme.ts";
|
||||
import * as ElectronWindow from "../../electron/ElectronWindow.ts";
|
||||
import * as IpcChannels from "../channels.ts";
|
||||
import { makeIpcMethod, makeSyncIpcMethod } from "../DesktopIpc.ts";
|
||||
import { resolveWslPickFolderDefaultPath } from "../../wsl/wslPathParsing.ts";
|
||||
import {
|
||||
extractDistroFromUncPath,
|
||||
resolveWslPickFolderDefaultPath,
|
||||
wslUncPathToLinuxPath,
|
||||
} from "../../wsl/wslPathParsing.ts";
|
||||
|
||||
const ContextMenuPosition = Schema.Struct({
|
||||
x: Schema.Number,
|
||||
@@ -144,7 +148,23 @@ export const pickFolder = makeIpcMethod({
|
||||
owner: yield* electronWindow.focusedMainOrFirst,
|
||||
defaultPath,
|
||||
});
|
||||
return Option.getOrNull(selectedPath);
|
||||
if (Option.isNone(selectedPath)) {
|
||||
return null;
|
||||
}
|
||||
if (!useWsl) {
|
||||
return selectedPath.value;
|
||||
}
|
||||
|
||||
const linuxUncPath = wslUncPathToLinuxPath(selectedPath.value);
|
||||
if (linuxUncPath !== null) {
|
||||
return linuxUncPath;
|
||||
}
|
||||
|
||||
const converted = yield* wslEnvironment.windowsToWslPath(
|
||||
extractDistroFromUncPath(selectedPath.value) ?? wslDistro,
|
||||
selectedPath.value,
|
||||
);
|
||||
return Option.getOrElse(converted, () => selectedPath.value);
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -546,20 +546,8 @@ export const layer = Layer.effect(
|
||||
return resolved;
|
||||
}).pipe(Effect.withSpan("desktop.wsl.getUserHome"));
|
||||
|
||||
// Cache the distro IP per distro for the life of the desktop
|
||||
// process; WSL's eth0 IP only changes on full WSL restarts (which
|
||||
// also restart the orchestrator's instance), so we don't need to
|
||||
// re-probe on every config resolve.
|
||||
const distroIpCache = new Map<string, string>();
|
||||
const getDistroIp = (distro: string | null) =>
|
||||
Effect.gen(function* () {
|
||||
const key = distro ?? "__default__";
|
||||
const cached = distroIpCache.get(key);
|
||||
if (cached !== undefined) return Option.some(cached);
|
||||
const resolved = yield* provideSpawner(getDistroIpImpl(distro));
|
||||
if (Option.isSome(resolved)) distroIpCache.set(key, resolved.value);
|
||||
return resolved;
|
||||
}).pipe(Effect.withSpan("desktop.wsl.getDistroIp"));
|
||||
provideSpawner(getDistroIpImpl(distro)).pipe(Effect.withSpan("desktop.wsl.getDistroIp"));
|
||||
|
||||
return DesktopWslEnvironment.of({
|
||||
isAvailable,
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
parseWslDistroList,
|
||||
resolveWslHomeUncPath,
|
||||
resolveWslPickFolderDefaultPath,
|
||||
wslUncPathToLinuxPath,
|
||||
} from "./wslPathParsing.ts";
|
||||
|
||||
function makeUtf16LeBuffer(text: string): Buffer {
|
||||
@@ -97,6 +98,24 @@ describe("extractDistroFromUncPath", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("wslUncPathToLinuxPath", () => {
|
||||
it("maps WSL UNC paths back to Linux absolute paths", () => {
|
||||
expect(wslUncPathToLinuxPath("\\\\wsl.localhost\\Ubuntu-22.04\\home\\josh\\repo")).toBe(
|
||||
"/home/josh/repo",
|
||||
);
|
||||
});
|
||||
|
||||
it("maps a distro UNC root to Linux root", () => {
|
||||
expect(wslUncPathToLinuxPath("\\\\wsl$\\Debian")).toBe("/");
|
||||
expect(wslUncPathToLinuxPath("\\\\wsl.localhost\\Debian\\")).toBe("/");
|
||||
});
|
||||
|
||||
it("rejects invalid distro names and non-WSL paths", () => {
|
||||
expect(wslUncPathToLinuxPath("\\\\wsl.localhost\\bad!name\\home")).toBeNull();
|
||||
expect(wslUncPathToLinuxPath("C:\\Users\\Josh\\repo")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveWslHomeUncPath", () => {
|
||||
const distros = [
|
||||
{ name: "Debian", isDefault: true, version: 2 as const },
|
||||
|
||||
@@ -48,6 +48,19 @@ export function extractDistroFromUncPath(windowsPath: string): string | null {
|
||||
return DISTRO_NAME_PATTERN.test(candidate) ? candidate : null;
|
||||
}
|
||||
|
||||
export function wslUncPathToLinuxPath(windowsPath: string): string | null {
|
||||
const match = /^\\\\(?:wsl\.localhost|wsl\$)\\([^\\]+)(?:\\(.*))?$/i.exec(windowsPath.trim());
|
||||
if (!match) return null;
|
||||
|
||||
const distro = match[1]!;
|
||||
if (!DISTRO_NAME_PATTERN.test(distro)) return null;
|
||||
|
||||
const rest = match[2] ?? "";
|
||||
if (rest.length === 0) return "/";
|
||||
|
||||
return `/${rest.split("\\").filter(Boolean).join("/")}`;
|
||||
}
|
||||
|
||||
export function resolveWslHomeUncPath(
|
||||
config: WslConfig,
|
||||
distros: readonly WslDistro[],
|
||||
|
||||
@@ -63,18 +63,18 @@ let pendingReconcileRun: Promise<void> | null = null;
|
||||
|
||||
// Backoff schedule for the auto-retry loop. WSL cold boot routinely
|
||||
// takes 30-60 seconds (distro spin-up + node-pty preflight + node
|
||||
// startup + migrations), and the backend's desktop-bootstrap grant
|
||||
// has a 5-minute TTL after seeding. This schedule comfortably covers
|
||||
// the cold-boot window while leaving headroom inside the TTL.
|
||||
// startup + migrations). The backend's desktop-bootstrap grant lives
|
||||
// for the backend process, so this budget is about user feedback rather
|
||||
// than credential expiry.
|
||||
const AUTO_RETRY_DELAYS_MS = [2_000, 4_000, 8_000, 16_000, 30_000, 45_000, 60_000, 60_000] as const;
|
||||
let autoRetryHandle: ReturnType<typeof setTimeout> | null = null;
|
||||
let autoRetryAttempt = 0;
|
||||
|
||||
// Latched once we've confirmed the user has no WSL backend configured
|
||||
// on this host. The auto-retry loop polls getLocalEnvironmentBootstraps
|
||||
// every few seconds for up to ~4 minutes (the desktop-bootstrap TTL
|
||||
// window); on machines where the user will never enable WSL that's
|
||||
// just wasted IPC. setWslBackendEnabled IPC handlers in the settings
|
||||
// every few seconds for a bounded window; on machines where the user
|
||||
// will never enable WSL that's just wasted IPC. setWslBackendEnabled
|
||||
// IPC handlers in the settings
|
||||
// page already call reconcile with resetBudget: true, so flipping the
|
||||
// switch on later resumes the loop. We default to false (keep
|
||||
// retrying) so any pre-existing WSL setup still gets retried during
|
||||
@@ -474,8 +474,7 @@ function runReconcile(options: { readonly resetBudget: boolean }): Promise<void>
|
||||
// concurrent calls share a single underlying reconcile pass. When a
|
||||
// secondary's registration fails (typical cause: WSL backend still
|
||||
// cold-booting), an internal backoff loop keeps retrying until either
|
||||
// the secondary lands in the registry or the desktop-bootstrap TTL
|
||||
// runs out and we give up.
|
||||
// the secondary lands in the registry or the retry budget runs out.
|
||||
export function reconcileLocalSecondaryEnvironments(): Promise<void> {
|
||||
return runReconcile({ resetBudget: true });
|
||||
}
|
||||
|
||||
@@ -1819,10 +1819,9 @@ export function startEnvironmentConnectionService(queryClient: QueryClient): ()
|
||||
|
||||
// Bring up the desktop-managed secondary local environments (today
|
||||
// just the WSL backend, if enabled). The reconcile call owns its
|
||||
// own retry loop: WSL cold boot routinely takes 30-60 seconds, and
|
||||
// the desktop-bootstrap grant on each backend has a 5-minute TTL.
|
||||
// own retry loop: WSL cold boot routinely takes 30-60 seconds.
|
||||
// reconcileLocalSecondaryEnvironments() backs off internally until
|
||||
// every secondary lands or the TTL window closes.
|
||||
// every secondary lands or the retry budget closes.
|
||||
void reconcileLocalSecondaryEnvironments();
|
||||
|
||||
const unsubscribeSavedEnvironments = useSavedEnvironmentRegistryStore.subscribe(() => {
|
||||
|
||||
Reference in new issue
Block a user