-
Notifications
You must be signed in to change notification settings - Fork 540
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
fetch() AbortSignal.timeout() does not work as expected #1926
Comments
cc @KhafraDev |
It seems, that the gc cleans up from some console logs TAP version 13
# Subtest: Allow the usage of custom implementation of AbortController
ok 1 - should be equal
1..1
ok 1 - Allow the usage of custom implementation of AbortController # time=13.181ms
# Subtest: allows aborting with custom errors
# Subtest: Using AbortSignal.timeout with cause
1..2
cleaned
aborting undefined
aborted I was wondering if using the diff --git a/lib/fetch/request.js b/lib/fetch/request.js
index 9764871..5a0e17d 100644
--- a/lib/fetch/request.js
+++ b/lib/fetch/request.js
@@ -30,6 +30,7 @@ const { URLSerializer } = require('./dataURL')
const { kHeadersList } = require('../core/symbols')
const assert = require('assert')
const { setMaxListeners, getEventListeners, defaultMaxListeners } = require('events')
+const { aborted } = require('util');
let TransformStream = globalThis.TransformStream
@@ -354,17 +355,12 @@ class Request {
if (signal.aborted) {
ac.abort(signal.reason)
} else {
- const acRef = new WeakRef(ac)
- const abort = function () {
- acRef.deref()?.abort(this.reason)
- }
if (getEventListeners(signal, 'abort').length >= defaultMaxListeners) {
setMaxListeners(100, signal)
}
- signal.addEventListener('abort', abort, { once: true })
- requestFinalizer.register(this, { signal, abort })
+ aborted(signal, this).then(() => ac.abort(signal.reason))
}
} Intuition suggests that when |
It's sufficient that the finalizer removes the closure. Fixes: #1926
It's sufficient that the finalizer removes the closure. Fixes: #1926
Sorry, but this change breaks my service. |
in the original issue, in the description, vary the small portion of code to reproduce it. Basically, it happened constantly if the argument of the |
It's sufficient that the finalizer removes the closure. Fixes: nodejs#1926
It's sufficient that the finalizer removes the closure. Fixes: nodejs#1926
Bug Description
It seems passing
{ signal: AbortSignal.timeout(50) }
tofetch()
is not taken into consideration.Reproducible By
Run
node test/fetch/abort.js
. TheAbortSignal.timeout()
test should pass immediately but it waits for 30s. This is the output:Expected Behavior
The
fetch
request should be completed in the expected timeout.Environment
Node 18 and 19, on both Windows and Mac OS X.
The text was updated successfully, but these errors were encountered: