Skip to content
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

fs: add signal option to fs.stat() #57775

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

mertcanaltin
Copy link
Member

@mertcanaltin mertcanaltin commented Apr 6, 2025

add signal option to fs.stat() for #57751

@nodejs-github-bot nodejs-github-bot added fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. labels Apr 6, 2025
Copy link

codecov bot commented Apr 6, 2025

Codecov Report

Attention: Patch coverage is 95.12195% with 2 lines in your changes missing coverage. Please review.

Project coverage is 90.24%. Comparing base (964e41c) to head (99ec837).
Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
lib/fs.js 95.12% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main   #57775    +/-   ##
========================================
  Coverage   90.23%   90.24%            
========================================
  Files         630      630            
  Lines      185518   185707   +189     
  Branches    36369    36412    +43     
========================================
+ Hits       167401   167587   +186     
+ Misses      11005    10999     -6     
- Partials     7112     7121     +9     
Files with missing lines Coverage Δ
lib/fs.js 98.22% <95.12%> (-0.05%) ⬇️

... and 26 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.

Copy link
Member

@LiviaMedeiros LiviaMedeiros left a comment

Choose a reason for hiding this comment

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

The commit message after subsystem should start with imperative verb and probably be more specific, maybe something like fs: add signal option to fs.stat()?

options.signal.addEventListener('abort', onAbort, { once: true });
}

req.oncomplete = (err, stats) => {
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocking concern, since oncomplete is our happy path here: this code paired with makeStatsCallback essentially wraps the callback twice. Maybe we can somehow avoid this, even at the cost of making abort paths slower and uglier.

Copy link
Member Author

@mertcanaltin mertcanaltin Apr 6, 2025

Choose a reason for hiding this comment

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

I wonder if you think this method is good?

To avoid wrapping the callback twice during the happy path, I do not wrap the callback at the beginning, I wrap it with a one-time makeStatsCallback in oncomplete after the abort check. When the abort condition occurs, I call the normal callback directly.

Copy link
Member

Choose a reason for hiding this comment

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

This is not perfect (we still validate callback twice and wrap twice inside the happy path), but I don't see perfect solution without rewriting all functions that use makeStatsCallback in the same way.
A good compromise for now would be adding a TODO comment here and optimizing it later.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can I leave it as it is now and add todo?

Copy link
Member Author

@mertcanaltin mertcanaltin Apr 11, 2025

Choose a reason for hiding this comment

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

I try added to this line 28bc2c3

@mertcanaltin mertcanaltin force-pushed the mert/feat/fs-abort-signal branch from 291c8a6 to 911f8da Compare April 6, 2025 21:02
@mertcanaltin mertcanaltin changed the title fs: added AbortSignal support fs: add signal option to fs.stat() Apr 6, 2025
@mertcanaltin
Copy link
Member Author

The commit message after subsystem should start with imperative verb and probably be more specific, maybe something like fs: add signal option to fs.stat()?

thank you very much, I will be more careful with this, sometimes I make the wrong sentence 🙏

@LiviaMedeiros LiviaMedeiros added the semver-minor PRs that contain new features and should be released in the next minor version. label Apr 6, 2025
@mertcanaltin mertcanaltin force-pushed the mert/feat/fs-abort-signal branch from f9b0d0d to 9fcffb4 Compare April 8, 2025 08:03
@jazelly jazelly added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 11, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 11, 2025
@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@LiviaMedeiros LiviaMedeiros left a comment

Choose a reason for hiding this comment

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

Doesn't necessarily have to be in scope of this PR, but i think we'll also need signal option for Sync and Promises API of this function, and also for the lstat version; ideally within same semver-minor release so there's no discrepancy between these functions.

Copy link
Member

@targos targos left a comment

Choose a reason for hiding this comment

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

Test is writing a temporary file in the cwd. It should use common API instead

@jasnell jasnell requested a review from targos April 12, 2025 17:44
@jasnell
Copy link
Member

jasnell commented Apr 13, 2025

@mertcanaltin ... can you please remove the merge commit from this and use rebase instead to catch it up?

@mertcanaltin mertcanaltin force-pushed the mert/feat/fs-abort-signal branch from 171a72d to 99ec837 Compare April 13, 2025 17:01
@mertcanaltin
Copy link
Member Author

@mertcanaltin ... can you please remove the merge commit from this and use rebase instead to catch it up?

thank you I used rebase

@nodejs-github-bot
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants