Skip to content

Conversation

LiviaMedeiros
Copy link
Member

@LiviaMedeiros LiviaMedeiros commented Jun 26, 2025

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

codecov bot commented Jun 26, 2025

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 3 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 on lines 4080 to 4153
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
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
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
Member Author

Choose a reason for hiding this comment

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

Sure, added.

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

@aduh95 aduh95 left a comment

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
Member Author

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

@LiviaMedeiros LiviaMedeiros force-pushed the fs-deprecate-dir-close-gc branch from 741088b to 8ff0b20 Compare September 12, 2025 12:17
@nodejs-github-bot
Copy link
Collaborator

@aduh95
Copy link
Contributor

aduh95 commented Sep 12, 2025

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

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants