Skip to content
Open
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
20 changes: 20 additions & 0 deletions scripts/runner.node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ if (isBuildkite) {

let coresDir;

// Declared before the first top-level `await spawnSafe(...)` below — spawnSafe
// is a hoisted function declaration that references this; with the const lower
// in the file the Linux-only coredump sysctl call hit the TDZ.
/** @type {Set<import("node:child_process").ChildProcess>} */
const activeSubprocesses = new Set();

if (options["coredump-upload"]) {
// this sysctl is set in bootstrap.sh to /var/bun-cores-$distro-$release-$arch
const sysctl = await spawnSafe({ command: "sysctl", args: ["-n", "kernel.core_pattern"] });
Comment thread
claude[bot] marked this conversation as resolved.
Expand Down Expand Up @@ -945,6 +951,7 @@ async function spawnSafe(options) {
subprocess.kill(9);
}
}
activeSubprocesses.delete(subprocess);
resolve();
};
await new Promise(resolve => {
Expand Down Expand Up @@ -975,6 +982,7 @@ async function spawnSafe(options) {
env,
});
subprocess.on("spawn", () => {
activeSubprocesses.add(subprocess);
timestamp = Date.now();
timer = setTimeout(() => done(resolve), timeout);
});
Expand Down Expand Up @@ -2350,6 +2358,18 @@ function isAlwaysFailure(error) {
function onExit(signal) {
const label = `${getAnsi("red")}Received ${signal}, exiting...${getAnsi("reset")}`;
startGroup(label, () => {
// Windows: children spawned without `detached` are assigned to this
// process's Job Object with JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE, so
// process.exit() below already terminates the whole tree — nothing to
// do here. POSIX: Buildkite cancel sends SIGTERM to the runner PID only
// (not the group), so orphans survive unless we kill them explicitly.
if (!isWindows) {
for (const proc of activeSubprocesses) {
try {
proc.kill(9);
} catch {}
}
}
process.exit(getExitCode("cancel"));
});
}
Expand Down
Loading