You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fs: opendirSync() leaks directory handle on error #58854
How often does it reproduce? Is there a required condition?
Always, assuming GC runs.
What is the expected behavior? Why is that the expected behavior?
The "successfully got" should not be printed.
The catched error must be ERR_OUT_OF_RANGE because of bad bufferSize.
The dir should be either:
An instance of fs.Dir that we can closeSync() gracefully
undefined assuming opendirSync internally did cleanup
And most importantly, this code must not emit any warnings.
What do you see instead?
dir is: undefinederroris: RangeError[ERR_OUT_OF_RANGE]: Thevalueof"options.bufferSize"isoutofrange.Itmustbeaninteger.ReceivedInfinityatnewDir(node:internal/fs/dir:61:5)atObject.opendirSync(node:internal/fs/dir:351:10)
at file:///tmp/test.mjs:5:14atModuleJob.run(node:internal/modules/esm/module_job:372:25)atasynconImport.tracePromise.__proto__(node:internal/modules/esm/loader:665:26)atasyncasyncRunEntryPointWithESMLoader(node:internal/modules/run_main:99:5){code: 'ERR_OUT_OF_RANGE'}(node:8286) Warning: Closingdirectoryhandleongarbagecollection(Use`node --trace-warnings ...`toshowwherethewarningwascreated)
Which means: dir stays undefined so we can not do anything about it, but the internal directory handle remains open until GC hunts it down.
Additional information
I haven't checked if fsPromises.opendir nor fs.opendir have similar problem but most likely they do.
I think this can be fixed on JS side, the patch is WIP.
Activity
fs: close dir before throwing if `options.bufferSize` is invalid
fs: close dir before throwing if `options.bufferSize` is invalid
fs: close dir before throwing if `options.bufferSize` is invalid
fs: close dir before throwing if `options.bufferSize` is invalid