Skip to content

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

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

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

@LiviaMedeirosLiviaMedeiros commented Jun 26, 2025

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

@LiviaMedeirosLiviaMedeiros 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-botnodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Jun 26, 2025
@LiviaMedeiros
LiviaMedeirosforce-pushed the fs-deprecate-dir-close-gc branch 3 times, most recently from 719ebb4 to 39e8ae5CompareJune 26, 2025 18:31
@codecov

codecovBot commented Jun 26, 2025

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 linesPatch %Lines
src/node_dir.cc90.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 linesCoverage Δ
src/env-inl.h93.68% <100.00%> (+0.06%)⬆️
src/env.h98.14% <ø> (ø)
src/node_dir.cc70.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 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.

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.

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

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Sure, added.

@LiviaMedeiros
LiviaMedeirosforce-pushed the fs-deprecate-dir-close-gc branch from 39e8ae5 to c60424bCompareSeptember 10, 2025 10:05

@aduh95aduh95 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.

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

@LiviaMedeiros

Copy link
Copy Markdown
MemberAuthor

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

@LiviaMedeiros
LiviaMedeirosforce-pushed the fs-deprecate-dir-close-gc branch from 741088b to 8ff0b20CompareSeptember 12, 2025 12:17
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@aduh95

Copy link
Copy Markdown
Contributor

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

@github-actions

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.

Sign up for freeto 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++.deprecationsIssues and PRs related to deprecations.fsIssues and PRs related to the fs subsystem / file system.needs-ciPRs that need a full CI run.semver-majorPRs 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.

3 participants

@LiviaMedeiros@nodejs-github-bot@aduh95