Skip to content

Commit 07fac6c

Browse files
authored
fix: retry on EMFILE when writing autofix results (#19926)
* fix: retry on EMFILE when writing autofix results * chore: update test
1 parent 35cf44c commit 07fac6c

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

lib/eslint/eslint.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,11 @@ class ESLint {
530530
throw new Error("'results' must be an array");
531531
}
532532

533+
const retryCodes = new Set(["ENFILE", "EMFILE"]);
534+
const retrier = new Retrier(error => retryCodes.has(error.code), {
535+
concurrency: 100,
536+
});
537+
533538
await Promise.all(
534539
results
535540
.filter(result => {
@@ -541,7 +546,9 @@ class ESLint {
541546
path.isAbsolute(result.filePath)
542547
);
543548
})
544-
.map(r => fs.writeFile(r.filePath, r.output)),
549+
.map(r =>
550+
retrier.retry(() => fs.writeFile(r.filePath, r.output)),
551+
),
545552
);
546553
}
547554

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
22
rules: {
3-
"no-unused-vars": "error"
3+
"capitalized-comments": "error"
44
}
55
};

tools/check-emfile-handling.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function generateFiles() {
6363

6464
for (let i = 0; i < FILE_COUNT; i++) {
6565
const fileName = `file_${i}.js`;
66-
const fileContent = `// This is file ${i}`;
66+
const fileContent = `// this is file ${i}`;
6767

6868
fs.writeFileSync(`${OUTPUT_DIRECTORY}/${fileName}`, fileContent);
6969
}
@@ -97,7 +97,7 @@ generateFiles();
9797

9898
console.log("Running ESLint...");
9999
execSync(
100-
`node bin/eslint.js ${OUTPUT_DIRECTORY} -c ${CONFIG_DIRECTORY}/eslint.config.js`,
100+
`node bin/eslint.js ${OUTPUT_DIRECTORY} -c ${CONFIG_DIRECTORY}/eslint.config.js --fix`,
101101
{ stdio: "inherit" },
102102
);
103103
console.log("✅ No errors encountered running ESLint.");

0 commit comments

Comments
 (0)