mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Fixes #9404
This commit is contained in:
8
packages/bun-types/bun.d.ts
vendored
8
packages/bun-types/bun.d.ts
vendored
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
7
test/js/bun/spawn/spawn_waiter_thread-fixture.js
generated
Normal file
7
test/js/bun/spawn/spawn_waiter_thread-fixture.js
generated
Normal 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();
|
||||
27
test/js/bun/spawn/spawn_waiter_thread.test.ts
Normal file
27
test/js/bun/spawn/spawn_waiter_thread.test.ts
Normal 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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user