fix(electron): stop waiting for a login shell that already timed out once

After the first wait for a hung `$SHELL -ilc env` runs out, later
bare-name player launches and Linux mpv probes proceed at once instead
of each waiting the full limit again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
4grayandClaude Opus 5.5 committed 2026-10-03 08:53:27 +02:00
1 parent ea7d6f6700
commit 0589156941
2 files changed
+17 -2

No files matched your search

@@ -84,6 +84,11 @@ describe('login shell PATH', () => {
const stuck = loadModule();
stuck.scheduleDeferredFixPath(() => new Promise(() => undefined));
await expect(stuck.waitForLoginShellPath(5)).resolves.toBeUndefined();
// Later spawns do not wait out the limit again (the test would time
// out on this one otherwise).
await expect(
stuck.waitForLoginShellPath(60_000)
).resolves.toBeUndefined();
});
it('lets spawns go immediately on Windows', async () => {
@@ -32,17 +32,27 @@ const loginShellPathSettled: Promise<void> =
/** Upper bound for a waiting spawn when the login shell never returns. */
export const LOGIN_SHELL_PATH_WAIT_LIMIT_MS = 10_000;
// Set once a wait has run out: a shell that hung that long is not waited
// for again, so one broken profile delays one launch, not every launch.
let loginShellPathWaitExpired = false;
/**
* Resolves once the login shell PATH lookup has finished (successfully or
* not), at the latest after `limitMs`; immediately on Windows.
* not), at the latest after `limitMs`; immediately on Windows and after a
* previous wait has run out.
*/
export function waitForLoginShellPath(
limitMs = LOGIN_SHELL_PATH_WAIT_LIMIT_MS
): Promise<void> {
if (loginShellPathWaitExpired) {
return Promise.resolve();
}
let timer: NodeJS.Timeout | undefined;
const limit = new Promise<void>((resolve) => {
timer = setTimeout(resolve, limitMs);
timer = setTimeout(() => {
loginShellPathWaitExpired = true;
resolve();
}, limitMs);
});
return Promise.race([loginShellPathSettled, limit]).finally(() =>
clearTimeout(timer)