Visitar URL original
test: update `EMFILE` error generation for Node.js 26.9.0 compatibili… · eslint/eslint@92086c8 · GitHub
Skip to content

Commit 92086c8

Browse files
authored
test: update EMFILE error generation for Node.js 26.9.0 compatibility (#21330)
1 parent 9ac7eb6 commit 92086c8

1 file changed

Lines changed: 12 additions & 19 deletions

File tree

‎tools/check-emfile-handling.js‎

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
//------------------------------------------------------------------------------
1111

1212
const fs = require("node:fs");
13-
const { writeFile } = require("node:fs/promises");
1413
const { execSync } = require("node:child_process");
1514
const os = require("node:os");
1615

@@ -76,28 +75,22 @@ function generateFiles() {
7675
}
7776

7877
/**
79-
* Generates an EMFILE error by writing to all files in the output directory.
80-
* Since Node.js 26.8.0, `readFile()` runs open, fstat, read, and close in a
81-
* single thread pool task, so concurrent reads no longer accumulate file
82-
* descriptors and cannot trigger EMFILE (https://github.com/nodejs/node/pull/65327).
83-
* Concurrent writes still can, and writing is also what `--fix` does above.
84-
* @returns {undefined}
78+
* Generates an EMFILE error by opening files one at a time and holding the
79+
* descriptors until the operating system refuses to open another file.
80+
* @returns {Promise<void>}
8581
*/
8682
async function generateEmFileError() {
87-
const results = await Promise.allSettled(
88-
Array.from({ length: FILE_COUNT }, (_, i) => {
89-
const fileName = `file_${i}.js`;
83+
const fds = [];
9084

91-
return writeFile(
92-
`${OUTPUT_DIRECTORY}/${fileName}`,
93-
"// Overwritten",
94-
);
95-
}),
96-
);
97-
const failedResult = results.find(({ status }) => status === "rejected");
85+
try {
86+
for (let i = 0; i < FILE_COUNT; i++) {
87+
const fileName = `file_${i}.js`;
88+
const fd = fs.openSync(`${OUTPUT_DIRECTORY}/${fileName}`);
9889

99-
if (failedResult?.reason) {
100-
throw failedResult.reason;
90+
fds.push(fd);
91+
}
92+
} finally {
93+
fds.forEach(fs.closeSync);
10194
}
10295
}
10396

0 commit comments

Comments
 (0)