Repository navigation
Unexpected error when using signal with reason in fetch #49557
Description
Activity
- addedfetchIssues and PRs related to the Fetch API.Issues and PRs related to the Fetch API.
on Sep 9, 2023 This also happens in node v20.6.1
@alexkorsun the underlaying issue is with https://github.com/nodejs/undici, and the issue here is the
reasonvalue is a string, and not an actual error.
Thisreasonis being passed intoError. captureStackTracewhich expects an object, and crashes when receiving a string (and any other non-object).This was already fixed in nodejs/undici#2243, which was released in
undici@5.24.0that did not yet reach Node (a PR for that is open: #49559)Reacted by Steven Luscher- linked a pull request that will close this issuedeps: update undici to 5.25.2 #49559
on Sep 13, 2023 node:internal/deps/undici/undici:11372 Error.captureStackTrace(err, this); ^ TypeError: invalid_argument at Function.captureStackTrace (<anonymous>) at Object.fetch (node:internal/deps/undici/undici:11372:11) Node.js v20.9.0
Reacted by Pete@atlowChemi Can this issue be reopened please?
I am still seeing this issue in Node 20.10.0 (with Undici 5.26.4, based on the changelog).
I even tried Node 20.8.0 (with Undici 5.24.0 - which was the version you mentioned) and I got the same error.Reacted by Steven Luscher@ShadowLNC does the code above reproduce the issue for you?
CC @nodejs/undici
@atlowChemi Using the code from the original issue description, I do indeed get the
TypeErroras described.For my other testsing I was using this one-line script
fetch('https://example.com', {signal: AbortSignal.abort("fake error")});- output from the REPL is as follows (showingundefinedreason as well as string value)> fetch('https://example.com', {signal: AbortSignal.abort()}); Promise { <pending>, [Symbol(async_id_symbol)]: 1082, [Symbol(trigger_async_id_symbol)]: 6 } > Uncaught: DOMException [AbortError]: This operation was aborted at Object.fetch (node:internal/deps/undici/undici:11730:11) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) > fetch('https://example.com', {signal: AbortSignal.abort("fake error")}); Promise { <pending>, [Symbol(async_id_symbol)]: 1139, [Symbol(trigger_async_id_symbol)]: 6 } > Uncaught TypeError: invalid_argument at Function.captureStackTrace (<anonymous>) at Object.fetch (node:internal/deps/undici/undici:11730:11) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) >
I came across this as I had the same issue even with v21.7.31. I fixed it with
new DOMException ( 'your reason' )as the parameter to the.abortmethod ofAbortController. This stopped this error from happening for me https://developer.mozilla.org/en-US/docs/Web/API/DOMExceptionCauses the undici error -
controller.abort()
Doesn't cause the error -controller.abort(new DOMException('reason'))Hope this helps anyone with similar issue.
FYI, the fix in undici was released in https://github.com/nodejs/undici/releases/tag/v6.3.0, and is available in Node in v22.0.0.
Reacted by Mati Horowitz
Version
18.17.1
Platform
Linux undefined 6.2.0-32-generic #32~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 18 10:40:13 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
fetch
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
The expected behavior is to have
[AbortError]: This operation was abortedwith the reason obtained from the signal.What do you see instead?
When
reason = undefinedWhen
reason = objectWhen
reason = stringAdditional information
No response