-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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 support for AbortSignal in readFile #35911
Conversation
It's probably worth noting what happens when a |
if (DOMException === undefined) | ||
DOMException = internalBinding('messaging').DOMException; | ||
return new DOMException(message, name); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why using a DOMException? As a user I would prefer to receive one of our error objects with a code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is recommended by the spec: https://dom.spec.whatwg.org/#aborting-ongoing-activities
Users are supposed to check for it with error.name === 'AbortError'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are telling our users to check for an error code. I think that should be the way to go here as well.
Note that I'd like the error code to be specific for fs.readFile, so it's easy to debug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mcollina this is what we use everywhere else that uses AbortSignals (like events.once and timers/promises) and everywhere in the web standard (like fetch). I feel strongly that this should be compatible with how exceptions work everywhere else.
A code
is already set on DOMExceptions (as ABORT_ERR ) see internal/per_context/domexception - we can recommend the code as the way to check rather than the name in the docs if you think that's better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've likely missed it everywhere else. This seems really hard to debug: users will not know what this aborterror is about in a complex application.
Let's not hold this for it.. I'll open an issue when I have the time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've likely missed it everywhere else. This seems really hard to debug: users will not know what this aborterror is about in a complex application.
Why? Would it help if this had a different .code
? I am happy to set the code
to something different here and reject with a subclass if you think that improves DX. I can also do that for timers (though like you said probably better in a different PX).
Note I'm not convinced DX is actually better with "different aborts cancel with different code
s since by far the most common the use case I saw is checking for cancellation (in general) to ignore the error (since cancellation is not an error most times). Users can also figure where cancellation came from from the stack trace.
Let's not hold this for it.. I'll open an issue when I have the time.
Sure, note you are currently blocking - is that intentional?
(Sorry I made a mess from the mobile interface). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
838cffb
to
ad6eac3
Compare
Commit Queue failed- Loading data for nodejs/node/pull/35911 ✔ Done loading data for nodejs/node/pull/35911 ----------------------------------- PR info ------------------------------------ Title fs: add support for AbortSignal in readFile (#35911) ⚠ Could not retrieve the email or name of the PR author's from user's GitHub profile! Branch benjamingr:readfile-abort-signal -> nodejs:master Labels fs, semver-minor Commits 1 - fs: add support for AbortSignal in readFile Committers 1 - Benjamin Gruenbaum PR-URL: https://github.com/nodejs/node/pull/35911 Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Matteo Collina Reviewed-By: Rich Trott Reviewed-By: Michaël Zasso ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/35911 Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Matteo Collina Reviewed-By: Rich Trott Reviewed-By: Michaël Zasso -------------------------------------------------------------------------------- ⚠ Commits were pushed since the last review: ⚠ - fs: add support for AbortSignal in readFile ✖ Last GitHub CI failed ℹ Last Full PR CI on 2020-11-05T18:03:50Z: https://ci.nodejs.org/job/node-test-pull-request/34099/ - Querying data for job/node-test-pull-request/34099/ ✔ Build data downloaded ✔ Last Jenkins CI successful ℹ This PR was created on Sun, 01 Nov 2020 16:25:00 GMT ✔ Approvals: 5 ✔ - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/35911#pullrequestreview-521239795 ✔ - Anna Henningsen (@addaleax): https://github.com/nodejs/node/pull/35911#pullrequestreview-521251093 ✔ - Matteo Collina (@mcollina) (TSC): https://github.com/nodejs/node/pull/35911#pullrequestreview-521540648 ✔ - Rich Trott (@Trott) (TSC): https://github.com/nodejs/node/pull/35911#pullrequestreview-521671149 ✔ - Michaël Zasso (@targos) (TSC): https://github.com/nodejs/node/pull/35911#pullrequestreview-521863433 -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncu Commit Queue action: https://github.com/nodejs/node/actions/runs/348132668 |
PR-URL: #35911 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
Landed manually in b5a136c |
PR-URL: #35911 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
Notable changes: * events: * getEventListeners static (Benjamin Gruenbaum) (#35991) * fs: * support abortsignal in writeFile (Benjamin Gruenbaum) (#35993) * add support for AbortSignal in readFile (Benjamin Gruenbaum) (#35911) * stream: * fix thrown object reference (Gil Pedersen) (#36065) PR URL: #36055
Notable changes: * events: * getEventListeners static (Benjamin Gruenbaum) (#35991) * fs: * support abortsignal in writeFile (Benjamin Gruenbaum) (#35993) * add support for AbortSignal in readFile (Benjamin Gruenbaum) (#35911) * stream: * fix thrown object reference (Gil Pedersen) (#36065) PR URL: #36055
Notable changes: * events: * getEventListeners static (Benjamin Gruenbaum) (#35991) * fs: * support abortsignal in writeFile (Benjamin Gruenbaum) (#35993) * add support for AbortSignal in readFile (Benjamin Gruenbaum) (#35911) * stream: * fix thrown object reference (Gil Pedersen) (#36065) PR URL: #36055
PR-URL: nodejs#35911 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
PR-URL: nodejs#35911 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
PR-URL: nodejs#35911 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
Refs: nodejs#33716 Refs: nodejs#35993 Refs: nodejs#35911
Refs: #33716 Refs: #35993 Refs: #35911 PR-URL: #39972 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
PR-URL: #39972 Refs: #33716 Refs: #35993 Refs: #35911 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Refs: #33716 Refs: #35993 Refs: #35911 PR-URL: #39972 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Add basic support for AbortSignal in
readFile
.This adds support just to
readFile
andfs.promises.readFile
and not anything else in FS (unless you include fileHandle.readFile).This is because it's significantly easier to do for readFile since the cancellation doesn't have to happen in libuv land and since readFile is a really heavy and pretty common action.
cc @jasnell @mcollina @addaleax