undici 6.19.5 → 6.19.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -34,8 +34,9 @@ const hasFinalizationRegistry = globalThis.FinalizationRegistry && process.versi
34
34
  let registry
35
35
 
36
36
  if (hasFinalizationRegistry) {
37
- registry = new FinalizationRegistry((stream) => {
38
- if (!stream.locked && !isDisturbed(stream) && !isErrored(stream)) {
37
+ registry = new FinalizationRegistry((weakRef) => {
38
+ const stream = weakRef.deref()
39
+ if (stream && !stream.locked && !isDisturbed(stream) && !isErrored(stream)) {
39
40
  stream.cancel('Response object has been garbage collected').catch(noop)
40
41
  }
41
42
  })
@@ -526,7 +527,12 @@ function fromInnerResponse (innerResponse, guard) {
526
527
  setHeadersGuard(response[kHeaders], guard)
527
528
 
528
529
  if (hasFinalizationRegistry && innerResponse.body?.stream) {
529
- registry.register(response, innerResponse.body.stream)
530
+ // If the target (response) is reclaimed, the cleanup callback may be called at some point with
531
+ // the held value provided for it (innerResponse.body.stream). The held value can be any value:
532
+ // a primitive or an object, even undefined. If the held value is an object, the registry keeps
533
+ // a strong reference to it (so it can pass it to the cleanup callback later). Reworded from
534
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry
535
+ registry.register(response, new WeakRef(innerResponse.body.stream))
530
536
  }
531
537
 
532
538
  return response
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "undici",
3
- "version": "6.19.5",
3
+ "version": "6.19.7",
4
4
  "description": "An HTTP/1.1 client, written from scratch for Node.js",
5
5
  "homepage": "https://undici.nodejs.org",
6
6
  "bugs": {