Skip to content
Closed
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
7 changes: 6 additions & 1 deletion tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ const assert = require("node:assert");

const TEST_TIMEOUT = 60000;

// see tests/win-exit-delay.cjs: without it every test crashes on exit under Node 24+ on Windows
const NODE_ARGS = process.platform === 'win32'
? `--require "${path.join(__dirname, 'win-exit-delay.cjs')}" `
: '';

const testPath = path.join(__dirname, 'tests');

let testCategories = fs.readdirSync(testPath).sort((a, b) => parseInt(a) - parseInt(b));
Expand Down Expand Up @@ -65,7 +70,7 @@ for (const testCategory of testCategories) {
};

let execTest = async (testPath) => {
return (await exec(`node ${testPath}`, {maxBuffer: 1024 * 1024 * 100})).stdout
return (await exec(`node ${NODE_ARGS}${testPath}`, {maxBuffer: 1024 * 1024 * 100})).stdout
}

try {
Expand Down
19 changes: 19 additions & 0 deletions tests/win-exit-delay.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Node 24 and later crash on Windows when process.exit() runs while undici still has
// keep-alive sockets open: "Assertion failed: !(handle->flags & UV_HANDLE_CLOSING),
// file src\win\async.c" (nodejs/node#56645). Every test here ends with process.exit()
// right after fetching, so they hit it, and the crash also loses whatever stdout was
// still buffered, which makes the captured output unreliable on top of the exit code.
//
// Letting the loop settle first avoids it. Preloaded by tests/index.js on win32 only,
// so nothing changes on Linux or macOS.

const EXIT_DELAY_MS = 100;

const realExit = process.exit.bind(process);

process.exit = (code) => {
if (code !== undefined) {
process.exitCode = code;
}
setTimeout(() => realExit(process.exitCode), EXIT_DELAY_MS);
};
Loading