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

fix: correct firing order of abort events #3169

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions lib/web/fetch/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const requestFinalizer = new FinalizationRegistry(({ signal, abort }) => {
signal.removeEventListener('abort', abort)
})

const dependentControllerMap = new WeakMap()

function buildAbort (acRef) {
return abort

Expand All @@ -57,6 +59,21 @@ function buildAbort (acRef) {
this.removeEventListener('abort', abort)

ac.abort(this.reason)

const controllerList = dependentControllerMap.get(ac.signal)

if (controllerList !== undefined) {
if (controllerList.size !== 0) {
for (const ref of controllerList) {
const ctrl = ref.deref()
if (ctrl !== undefined) {
ctrl.abort(this.reason)
}
}
controllerList.clear()
}
dependentControllerMap.delete(ac.signal)
}
}
}
}
Expand Down Expand Up @@ -754,11 +771,16 @@ class Request {
if (this.signal.aborted) {
ac.abort(this.signal.reason)
} else {
let list = dependentControllerMap.get(this.signal)
if (list === undefined) {
list = new Set()
dependentControllerMap.set(this.signal, list)
}
const acRef = new WeakRef(ac)
list.add(acRef)
util.addAbortListener(
this.signal,
() => {
ac.abort(this.signal.reason)
}
ac.signal,
buildAbort(acRef)
)
}

Expand Down
4 changes: 1 addition & 3 deletions test/wpt/status/fetch.status.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
"api": {
"abort": {
"general.any.js": {
"note": "TODO(@KhafraDev): Clone aborts with original controller can probably be fixed",
"fail": [
"Already aborted signal rejects immediately",
"Underlying connection is closed when aborting after receiving response - no-cors",
"Stream errors once aborted. Underlying connection closed.",
"Readable stream synchronously cancels with AbortError if aborted before reading",
"Clone aborts with original controller"
"Readable stream synchronously cancels with AbortError if aborted before reading"
]
},
"cache.https.any.js": {
Expand Down
Loading