-
Notifications
You must be signed in to change notification settings - Fork 300
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
Add abort reason to AbortSignal #1027
Conversation
With setting nits aside, I have a question - when no |
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.
With setting nits aside, I have a question - when no reason is given to AbortController.abort(), should AbortController.reason be undefined, or an AbortError? I think undefined is simpler and I prefer the option if there is no reason to create a new AbortError.
I think it's important to create a new AbortError so that author code can do something like
async function doSomething({ signal }) {
if (signal.aborted) {
throw signal.reason;
}
}
to propagate the error as expected. This is also how I would expect us to write the other specs, e.g. Fetch would say something like "If signal is aborted, then reject promise with signal's abort reason."
Hmm, I wonder if the property should be |
I don't have strong opinions about |
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.
The main logic looks great now.
I'm still interested to gather more opinions on reason
vs. abortReason
... maybe @jasnell can help represent other-ecosystems perspectives.
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 LGTM. It's a good idea. Having the reason default to an AbortError makes sense but I don't think it's entirely necessary.
I'll add this to both Node.js and Workers.
Thank you @jasnell! Do you have any opinions on the naming of the abort reason by the way (i.e. |
I think just 'reason' for the name works |
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.
Thanks, this looks good except for some nits.
I think it would be good to have some of the follow-up PRs against other specifications, e.g., Fetch, ready as well (at least in draft state) to ensure it works out and the complete flow can be reviewed.
Co-authored-by: Anne van Kesteren <annevk@annevk.nl>
Part of #1165, which discusses moving it instead to the AbortSignal's reason property per whatwg/dom#1027.
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.
Looks good! Excited for this as this will enable timeouts as well. As I mentioned above I think we should have the PRs against the other specifications as well (CI will complain, but that's okay) to get the full picture.
Co-authored-by: Anne van Kesteren <annevk@annevk.nl>
Thank you @annevk! I am working on the Streams and Fetch PRs so hopefully I can have that up soon. |
Implements whatwg/dom#1027.
…=testonly Automatic update from web-platform-tests DOM: tests for AbortSignal's reason See whatwg/dom#1027 for context. -- wpt-commits: 9c7dfd2809b6c3a209a2c4df43c1d6816e6bfc1b wpt-pr: 31291
…=testonly Automatic update from web-platform-tests DOM: tests for AbortSignal's reason See whatwg/dom#1027 for context. -- wpt-commits: 9c7dfd2809b6c3a209a2c4df43c1d6816e6bfc1b wpt-pr: 31291
See whatwg/dom#1027 for context.
Testing the rejected error is not really safe, especially if adopted for third-party code. This also makes for a smoother transition if node APIs adopt signal.reason. Refs: nodejs#40692 Refs: whatwg/dom#1027
This is done to prepare user code for signal.reason, which will allow custom errors to be thrown on aborts. Custom errors means that it will not be possible to conclusively determine if an error is from an `ac.abort()`, just by looking at it. By not declaring what error is thrown, node is also free to change it to `new DOMException(message, 'AbortError')` in a future release. This also avoids the possible addition of a public `AbortError` to node. The thrown errors will remain instances of the internal `AbortError` for now, to avoid effecting existing user code. While signal.aborted can be used to detect aborted errors in most cases, it does fully not work for the stream pipeline API, where individual streams are destroyed with `stream.destroy(new AbortError())`. Here the stream can no longer fully detect aborts. However, I don't think this is ever relevant, as streams should always perform the same cleanup logic, regardless of what error is passed. If it doesn't support a signal option, it does not make sense to include logic to handle signal aborts. Refs: nodejs#40692 Refs: nodejs#38361 Refs: whatwg/dom#1027
Following on from whatwg/dom#1027, with introduces custom abort reasons, this uses the AbortSignal's abort reason in the ReadableStreamPipeTo function. It also updates WritableStreamAbort to use the reason to signal abort. Closes #1165. Part of whatwg/dom#1030.
This CL follows whatwg/dom#1027, which adds an abort reason property[1] to DOM's AbortSignal API (i.e. signal.reason). This change also removes the aborted flag from the AbortSignal, and instead uses the "aborted" predicate[2] to do similar checks. [1] https://dom.spec.whatwg.org/#abortsignal-abort-reason [2] https://dom.spec.whatwg.org/#abortsignal-aborted Intent to Ship: https://groups.google.com/a/chromium.org/g/blink-dev/c/T6B5czAke1I Bug: 1263410 Change-Id: I25beb697d8e73dc73fdce2bc0d24b5e1bd52b78e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3293551 Reviewed-by: Kent Tamura <tkent@chromium.org> Reviewed-by: Yutaka Hirano <yhirano@chromium.org> Reviewed-by: Kentaro Hara <haraken@chromium.org> Commit-Queue: Nidhi Jaju <nidhijaju@chromium.org> Cr-Commit-Position: refs/heads/main@{#945295}
This is a follow-up to whatwg/dom#1027 ensuring that the fetch algorithm forwards the abort reason appropriately. Tests: web-platform-tests/wpt#35374.
This CL follows whatwg/dom#1027, which adds an abort reason property[1] to DOM's AbortSignal API (i.e. signal.reason). This change also removes the aborted flag from the AbortSignal, and instead uses the "aborted" predicate[2] to do similar checks. [1] https://dom.spec.whatwg.org/#abortsignal-abort-reason [2] https://dom.spec.whatwg.org/#abortsignal-aborted Intent to Ship: https://groups.google.com/a/chromium.org/g/blink-dev/c/T6B5czAke1I Bug: 1263410 Change-Id: I25beb697d8e73dc73fdce2bc0d24b5e1bd52b78e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3293551 Reviewed-by: Kent Tamura <tkent@chromium.org> Reviewed-by: Yutaka Hirano <yhirano@chromium.org> Reviewed-by: Kentaro Hara <haraken@chromium.org> Commit-Queue: Nidhi Jaju <nidhijaju@chromium.org> Cr-Commit-Position: refs/heads/main@{#945295} NOKEYCHECK=True GitOrigin-RevId: 155b2353a12c9e0173b8d33b32b115a2406a8131
Based on the discussion in whatwg/streams#1165, it was suggested that we add an abort reason property to AbortSignal. This PR makes the initial changes to the base primitives in the DOM spec, before we make changes to all other related specs that use the AbortSignal.
@domenic Is it okay if you please help take a look?
/cc @yutakahirano
Preview | Diff