Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"stylelint-config-recommended-scss": "^16.0.0",
"tiktoken": "^1.0.22",
"tinyglobby": "^0.2.14",
"tree-kill": "^1.2.2",
"tsx": "^4.20.3",
"typescript": "^5.8.3",
"yargs": "^18.0.0",
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion runner/orchestration/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export async function generateCodeAndAssess(options: {
? // Building can be really expensive. We likely should add support for "CPU hints" per environment.
// E.g. CLI building is really CPU intensive with ESBuild being multi-core.
// TODO: Follow-up on this and add CPU hints.
Math.floor(availableParallelism() * 0.4 * 0.5)
Math.floor(appConcurrency * 0.5)
: Infinity,
});

Expand Down
31 changes: 28 additions & 3 deletions runner/utils/kill-gracefully.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
import { ChildProcess } from 'child_process';
import treeKill from 'tree-kill';

function treeKillPromise(pid: number, signal: string): Promise<void> {
return new Promise((resolve, reject) => {
treeKill(pid, signal, (err) => {
if (err !== undefined) {
reject(err);
} else {
resolve(err);
}
});
});
}

export function killChildProcessGracefully(
child: ChildProcess,
timeoutInMs = 1000 * 10 // 10s
): Promise<void> {
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
// Process already exited.
if (child.exitCode !== null) {
resolve();
return;
}
const pid = child.pid;
if (pid === undefined) {
throw new Error(`No process ID for processed that should be killed.`);
}

// Watch for exiting, so that we can cancel the timeout(s) then.
Expand All @@ -18,10 +36,17 @@ export function killChildProcessGracefully(
});

// Send SIGTERM
child.kill('SIGTERM');
try {
await treeKillPromise(pid, 'SIGTERM');
} catch (e) {
console.error(
`Could not send "SIGTERM" for killing process. Trying "SIGKILL".`
);
}

// Start a timeout for the SIGKILL fallback
const sigkillTimeoutId = setTimeout(
() => child.kill('SIGKILL'),
() => treeKill(pid, 'SIGKILL'),
timeoutInMs
);
// Start another timeout to reject the promise if the child process never fires `exit` for some reasons.
Expand Down
Loading