-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
doc: deprecate closing fs.Dir on garbage collection
#59839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nodejs-github-bot
merged 2 commits into
nodejs:main
from
LiviaMedeiros:fs-deprecate-dir-close-gc-doconly
Sep 12, 2025
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4104,6 +4104,52 @@ The `node:_http_agent`, `node:_http_client`, `node:_http_common`, `node:_http_in | |
| `node:_http_outgoing` and `node:_http_server` modules are deprecated as they should be considered | ||
| an internal nodejs implementation rather than a public facing API, use `node:http` instead. | ||
|
|
||
| ### DEP0200: Closing fs.Dir on garbage collection | ||
|
|
||
| <!-- YAML | ||
| changes: | ||
| - version: REPLACEME | ||
| pr-url: https://github.com/nodejs/node/pull/59839 | ||
| description: Documentation-only deprecation. | ||
| --> | ||
|
|
||
| Type: Runtime | ||
|
|
||
| Allowing a [`fs.Dir`][] object to be closed on garbage collection is | ||
| deprecated. In the future, doing so might result in a thrown error that will | ||
| terminate the process. | ||
|
|
||
| Please ensure that all `fs.Dir` objects are explicitly closed using | ||
| `Dir.prototype.close()` or `using` keyword: | ||
|
|
||
| ```mjs | ||
| import { opendir } from 'node:fs/promises'; | ||
|
|
||
| { | ||
| await using dir = await opendir('/async/disposable/directory'); | ||
| } // Closed by dir[Symbol.asyncDispose]() | ||
|
|
||
| { | ||
| using dir = await opendir('/sync/disposable/directory'); | ||
| } // Closed by dir[Symbol.dispose]() | ||
|
Comment on lines
+4128
to
+4134
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding
dont-land-on-v22.x
|
||
|
|
||
| { | ||
| const dir = await opendir('/unconditionally/iterated/directory'); | ||
| for await (const entry of dir) { | ||
| // process an entry | ||
| } // Closed by iterator | ||
| } | ||
|
|
||
| { | ||
| let dir; | ||
| try { | ||
| dir = await opendir('/legacy/closeable/directory'); | ||
| } finally { | ||
| await dir?.close(); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| [DEP0142]: #dep0142-repl_builtinlibs | ||
| [NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf | ||
| [RFC 6066]: https://tools.ietf.org/html/rfc6066#section-3 | ||
|
|
@@ -4159,6 +4205,7 @@ an internal nodejs implementation rather than a public facing API, use `node:htt | |
| [`ecdh.setPublicKey()`]: crypto.md#ecdhsetpublickeypublickey-encoding | ||
| [`emitter.listenerCount(eventName)`]: events.md#emitterlistenercounteventname-listener | ||
| [`events.listenerCount(emitter, eventName)`]: events.md#eventslistenercountemitter-eventname | ||
| [`fs.Dir`]: fs.md#class-fsdir | ||
| [`fs.FileHandle`]: fs.md#class-filehandle | ||
| [`fs.access()`]: fs.md#fsaccesspath-mode-callback | ||
| [`fs.appendFile()`]: fs.md#fsappendfilepath-data-options-callback | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.