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: call explicitly unregister #2534

Merged
merged 1 commit into from
Dec 24, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/compat/dispatcher-weakref.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class CompatFinalizer {
})
}
}

unregister (key) {}
}

module.exports = function () {
Expand Down
18 changes: 17 additions & 1 deletion lib/fetch/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,18 @@ class Request {
const abort = function () {
const ac = acRef.deref()
if (ac !== undefined) {
// Currently, there is a problem with FinalizationRegistry.
// https://github.com/nodejs/node/issues/49344
// https://github.com/nodejs/node/issues/47748
// In the case of abort, the first step is to unregister from it.
// If the controller can refer to it, it is still registered.
// It will be removed in the future.
requestFinalizer.unregister(abort)

// Unsubscribe a listener.
// FinalizationRegistry will no longer be called, so this must be done.
this.removeEventListener('abort', abort)

ac.abort(this.reason)
}
}
Expand All @@ -388,7 +400,11 @@ class Request {
} catch {}

util.addAbortListener(signal, abort)
requestFinalizer.register(ac, { signal, abort })
// The third argument must be a registry key to be unregistered.
// Without it, you cannot unregister.
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry
// abort is used as the unregister key. (because it is unique)
requestFinalizer.register(ac, { signal, abort }, abort)
}
}

Expand Down