This commit is contained in:
Jarred Sumner
2024-03-14 08:00:24 +01:00
parent 9573c6e2b7
commit 85c4e87ccc
4 changed files with 44 additions and 6 deletions

View File

@@ -4195,19 +4195,19 @@ declare module "bun" {
};
/**
* The amount of CPU time used by the process, in nanoseconds.
* The amount of CPU time used by the process, in microseconds.
*/
cpuTime: {
/**
* User CPU time used by the process, in nanoseconds.
* User CPU time used by the process, in microseconds.
*/
user: number;
/**
* System CPU time used by the process, in nanoseconds.
* System CPU time used by the process, in microseconds.
*/
system: number;
/**
* Total CPU time used by the process, in nanoseconds.
* Total CPU time used by the process, in microseconds.
*/
total: number;
};

View File

@@ -849,9 +849,13 @@ const WaiterThreadPosix = struct {
_ = std.os.poll(&polls, std.math.maxInt(i32)) catch 0;
// Make sure we consume any pending signals
// Make sure we consume any pending:
// - signals
// - eventfd
// See https://github.com/oven-sh/bun/issues/9404
var buf: [1024]u8 = undefined;
_ = std.os.read(this.signalfd.cast(), &buf) catch 0;
while (bun.sys.read(this.signalfd.cast(), &buf).unwrap() catch 0 > 0) {}
while (bun.sys.read(this.eventfd.cast(), &buf).unwrap() catch 0 > 0) {}
} else {
var mask = std.os.empty_sigset;
var signal: c_int = std.os.SIG.CHLD;

View File

@@ -0,0 +1,7 @@
const { spawn } = require("child_process");
if (!process.env.BUN_GARBAGE_COLLECTOR_LEVEL || !process.env.BUN_FEATURE_FLAG_FORCE_WAITER_THREAD) {
throw new Error("This test must be run with BUN_GARBAGE_COLLECTOR_LEVEL and BUN_FEATURE_FLAG_FORCE_WAITER_THREAD");
}
spawn("sleep", ["infinity"]).ref();

View File

@@ -0,0 +1,27 @@
import { test, expect } from "bun:test";
import { spawn } from "bun";
import { bunEnv, bunExe } from "harness";
import { join } from "path";
if (process.platform === "linux") {
test("issue #9404", async () => {
const proc = spawn({
env: {
...bunEnv,
BUN_GARBAGE_COLLECTOR_LEVEL: "1",
BUN_FEATURE_FLAG_FORCE_WAITER_THREAD: "1",
},
stderr: "inherit",
cmd: [bunExe(), join(__dirname, "spawn_waiter_thread-fixture.js")],
});
setTimeout(() => {
proc.kill();
}, 1000);
await proc.exited;
const resourceUsage = proc.resourceUsage();
expect(resourceUsage?.cpuTime.total).toBeLessThan(750_000n);
});
}