Skip to content

Commit

Permalink
fix: terminate w/ aborted flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag authored and crysmags committed Feb 27, 2024
1 parent 4e35efb commit d106924
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const EE = require('events')
const { PassThrough, pipeline } = require('stream')

// https://fetch.spec.whatwg.org/#garbage-collection
const registry = new FinalizationRegistry(abort => {
const registry = new FinalizationRegistry((abort) => {
abort()
})

Expand All @@ -46,7 +46,7 @@ async function fetch (resource, init) {
terminated: false,
connection: null,
dump: false,
terminate ({ reason, aborted = reason?.name === 'AbortError' } = {}) {
terminate ({ reason, aborted } = {}) {
if (this.terminated) {
return
}
Expand Down Expand Up @@ -109,7 +109,7 @@ async function fetch (resource, init) {
abortFetch.call(context, p, request, responseObject)

// 3. Terminate the ongoing fetch with the aborted flag set.
context.terminate({ reason: new AbortError() })
context.terminate({ aborted: true })
},
{ once: true }
)
Expand Down Expand Up @@ -1401,7 +1401,10 @@ function httpNetworkFetch (

// 2. If e is an "AbortError" DOMException, then terminate the ongoing fetch with the aborted flag set.
// 3. Otherwise, terminate the ongoing fetch.
context.terminate({ reason: e })
context.terminate({
aborted: e.name === 'AbortError',
reason: e
})
}
})()

Expand All @@ -1427,7 +1430,7 @@ function httpNetworkFetch (
// 11. Let cancelAlgorithm be an action that terminates the ongoing
// fetch with the aborted flag set.
const cancelAlgorithm = () => {
context.terminate({ reason: new AbortError() })
context.terminate({ aborted: true })
}

// 12. Let highWaterMark be a non-negative, non-NaN number, chosen by
Expand Down

0 comments on commit d106924

Please sign in to comment.