Skip to content

Commit

Permalink
fix: correct firing order of abort events (#3169)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsctx authored Apr 26, 2024
1 parent 3f927b8 commit ed686fc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
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

0 comments on commit ed686fc

Please sign in to comment.