|
10 | 10 | //------------------------------------------------------------------------------ |
11 | 11 |
|
12 | 12 | const fs = require("node:fs"); |
13 | | -const { writeFile } = require("node:fs/promises"); |
14 | 13 | const { execSync } = require("node:child_process"); |
15 | 14 | const os = require("node:os"); |
16 | 15 |
|
@@ -76,28 +75,22 @@ function generateFiles() { |
76 | 75 | } |
77 | 76 |
|
78 | 77 | /** |
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>} |
85 | 81 | */ |
86 | 82 | 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 = []; |
90 | 84 |
|
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}`); |
98 | 89 |
|
99 | | - if (failedResult?.reason) { |
100 | | - throw failedResult.reason; |
| 90 | + fds.push(fd); |
| 91 | + } |
| 92 | + } finally { |
| 93 | + fds.forEach(fs.closeSync); |
101 | 94 | } |
102 | 95 | } |
103 | 96 |
|
|
0 commit comments