mirror of https://github.com/vuejs/vitepress
Content, include, route-template and search reads now run concurrently, so large sites can hit EMFILE/ENFILE. Route all async reads through a shared readFile util that retries with backoff. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>pull/5342/head
parent
3372516152
commit
da71173afc
@ -0,0 +1,19 @@
|
||||
import { readFile as fsReadFile } from 'node:fs/promises'
|
||||
|
||||
const retryCodes = new Set(['EMFILE', 'ENFILE'])
|
||||
|
||||
/**
|
||||
* Reads a file as utf8, retrying with backoff when the process is
|
||||
* temporarily out of file descriptors (EMFILE/ENFILE).
|
||||
*/
|
||||
export async function readFile(file: string): Promise<string> {
|
||||
for (let attempt = 0; ; attempt++) {
|
||||
try {
|
||||
return await fsReadFile(file, 'utf8')
|
||||
} catch (e) {
|
||||
const code = (e as NodeJS.ErrnoException).code
|
||||
if (attempt >= 9 || !code || !retryCodes.has(code)) throw e
|
||||
await new Promise((resolve) => setTimeout(resolve, 2 ** attempt * 10))
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue