FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fs: runtime deprecate closing `fs.Dir` on garbage collection by LiviaMedeiros · Pull Request #58850 · nodejs/node · GitHub

/ node Public

fs: runtime deprecate closing fs.Dir on garbage collection - #58850

Closed
LiviaMedeiros wants to merge 1 commit into
nodejs:mainfrom
LiviaMedeiros:fs-deprecate-dir-close-gc
Closed

fs: runtime deprecate closing fs.Dir on garbage collection#58850
LiviaMedeiros wants to merge 1 commit into
nodejs:mainfrom
LiviaMedeiros:fs-deprecate-dir-close-gc

Conversation

LiviaMedeiros commented Jun 26, 2025
edited
Loading

Copy link
Copy Markdown
Member

The DEP0137 is going to be End-of-Life in the next major release.

I think we should align closing fs.Dir on GC and deprecate it as well. Now that explicit resource management is available, closing dirs properly should become easier for userland.

Given that it already spams Warnings in stderr, it would make sense to make this deprecation runtime right away.

cc @nodejs/fs @nodejs/tsc

LiviaMedeiros added fs Issues and PRs related to the fs subsystem / file system. semver-major PRs that contain breaking changes and should be released in the next major version. needs-ci PRs that need a full CI run. deprecations Issues and PRs related to deprecations. labels Jun 26, 2025
nodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Jun 26, 2025
LiviaMedeiros force-pushed the fs-deprecate-dir-close-gc branch 3 times, most recently from 719ebb4 to 39e8ae5 Compare June 26, 2025 18:31

codecov Bot commented Jun 26, 2025
edited
Loading

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.75000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 88.26%. Comparing base (94422e8) to head (8ff0b20).
⚠️ Report is 2557 commits behind head on main.

Files with missing lines Patch % Lines
src/node_dir.cc 90.90% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #58850      +/-   ##
==========================================
- Coverage   88.28%   88.26%   -0.02%     
==========================================
  Files         702      702              
  Lines      206760   206773      +13     
  Branches    39776    39777       +1     
==========================================
- Hits       182531   182508      -23     
- Misses      16235    16269      +34     
- Partials     7994     7996       +2     
Files with missing lines Coverage Δ
src/env-inl.h 93.68% <100.00%> (+0.06%) ⬆️
src/env.h 98.14% <ø> (ø)
src/node_dir.cc 70.98% <90.90%> (+0.53%) ⬆️

... and 36 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread doc/api/deprecations.md
Comment on lines +4080 to +4097
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]()

{
let dir;
try {
dir = await opendir('/legacy/closeable/directory');
} finally {
await dir?.close();
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think this is lacking the (IMO) most prominent use-case for opendir: iterating on it. Can you add a test that iterates on a Dir and validates that it does not trigger any warning?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can you add the iteration example in this snippet as well please?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Sure, added.

LiviaMedeiros force-pushed the fs-deprecate-dir-close-gc branch from 39e8ae5 to c60424b Compare September 10, 2025 10:05

aduh95 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM. We should probably land this as doc-only first, if you can open another PR that lands first, that'd be great, otherwise I can do it for you

Copy link
Copy Markdown
Member Author

Sure, i'll make PR with doc-only version of this (or rather, formalizing already existing runtime warning as deprecation).

LiviaMedeiros force-pushed the fs-deprecate-dir-close-gc branch from 741088b to 8ff0b20 Compare September 12, 2025 12:17

Copy link
Copy Markdown
Collaborator

aduh95 commented Sep 12, 2025

Copy link
Copy Markdown
Contributor

@nodejs/tsc do we want this in v25.x? If so, we'd need at least one more approval

Copy link
Copy Markdown
Contributor

This pull request has been marked as stale due to 90 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.

github-actions Bot added the stale label Jul 28, 2026
avivkeller closed this Aug 9, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. deprecations Issues and PRs related to deprecations. fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. semver-major PRs that contain breaking changes and should be released in the next major version. stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL