Files
bun.sh/test/js/web/abort/abort.signal.ts
Jarred Sumner 964d4dac2c Rewrite AbortSignal.timeout (#21695)
### What does this PR do?

On Linux, AbortSignal.timeout created a file descriptor for each timeout
and did not keep the event loop alive when a timer was active. This is
fixed.

### How did you verify your code works?

Fewer flaky tests

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Claude <claude@anthropic.ai>
2025-08-08 23:07:19 -07:00

29 lines
659 B
TypeScript

using server2 = Bun.serve({
port: 0,
async fetch() {
await Bun.sleep(1000);
return new Response("test");
},
});
using server = Bun.serve({
port: 0,
error(error) {
return new Response(error.message, { status: 500 });
},
async fetch() {
const signal = AbortSignal.timeout(1);
return await fetch(server2.url.href, { signal });
},
});
let url = server.url.href;
const responses: Response[] = [];
for (let i = 0; i < 10; i++) {
responses.push(await fetch(url));
}
// we fail if any of the requests succeeded
const anySuccess = responses.some(res => res.status >= 200 && res.status < 500);
process.exit(anySuccess ? 1 : 0);