Skip to content

Commit 48f33d4

Browse files
committed
🤖 fix: avoid sync fs when resolving nice
1 parent 9bce96c commit 48f33d4

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

src/node/runtime/LocalBaseRuntime.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,35 @@ import { NON_INTERACTIVE_ENV_VARS } from "@/common/constants/env";
2222
import { getBashPath } from "@/node/utils/main/bashPath";
2323
import { EXIT_CODE_ABORTED, EXIT_CODE_TIMEOUT } from "@/common/constants/exitCodes";
2424
import { DisposableProcess } from "@/node/utils/disposableExec";
25-
import { expandTilde } from "./tildeExpansion";
2625
import { getInitHookPath, createLineBufferedLoggers } from "./initHook";
26+
import { expandTilde } from "./tildeExpansion";
27+
28+
let cachedNicePath: string | null | undefined;
29+
30+
async function resolveNicePath(): Promise<string | null> {
31+
if (cachedNicePath !== undefined) {
32+
return cachedNicePath;
33+
}
34+
35+
try {
36+
await fsPromises.access("/usr/bin/nice");
37+
cachedNicePath = "/usr/bin/nice";
38+
return cachedNicePath;
39+
} catch {
40+
// continue
41+
}
42+
43+
try {
44+
await fsPromises.access("/bin/nice");
45+
cachedNicePath = "/bin/nice";
46+
return cachedNicePath;
47+
} catch {
48+
// continue
49+
}
50+
51+
cachedNicePath = null;
52+
return cachedNicePath;
53+
}
2754

2855
/**
2956
* Abstract base class for local runtimes (both WorktreeRuntime and LocalRuntime).
@@ -70,13 +97,7 @@ export abstract class LocalBaseRuntime implements Runtime {
7097
const bashPath = getBashPath();
7198

7299
const shouldNice = options.niceness !== undefined && !isWindows;
73-
const nicePath = shouldNice
74-
? fs.existsSync("/usr/bin/nice")
75-
? "/usr/bin/nice"
76-
: fs.existsSync("/bin/nice")
77-
? "/bin/nice"
78-
: null
79-
: null;
100+
const nicePath = shouldNice ? await resolveNicePath() : null;
80101

81102
const spawnCommand = nicePath ?? bashPath;
82103
const spawnArgs =

0 commit comments

Comments
 (0)