From 8abfa7d83bac136ff4b5f29fec828be9ce135649 Mon Sep 17 00:00:00 2001 From: tsctx <91457664+tsctx@users.noreply.github.com> Date: Thu, 21 Dec 2023 17:42:32 +0900 Subject: [PATCH] fix: call explicitly unregister --- lib/compat/dispatcher-weakref.js | 2 ++ lib/fetch/request.js | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/compat/dispatcher-weakref.js b/lib/compat/dispatcher-weakref.js index a2fd0020416..463b29ca319 100644 --- a/lib/compat/dispatcher-weakref.js +++ b/lib/compat/dispatcher-weakref.js @@ -28,6 +28,8 @@ class CompatFinalizer { }) } } + + unregister (key) {} } module.exports = function () { diff --git a/lib/fetch/request.js b/lib/fetch/request.js index 85b8bb0df2f..5e99ef40947 100644 --- a/lib/fetch/request.js +++ b/lib/fetch/request.js @@ -34,7 +34,12 @@ const { getMaxListeners, setMaxListeners, getEventListeners, defaultMaxListeners const kAbortController = Symbol('abortController') -const requestFinalizer = new FinalizationRegistry(({ signal, abort }) => { +const requestFinalizer = new FinalizationRegistry(({ signal, abort, controller }) => { + // Currently FinalizationRegistry has a problem and will explicitly call unregister. + // https://github.com/nodejs/node/issues/49344 + // https://github.com/nodejs/node/issues/47748 + // It will be removed in the future. + requestFinalizer.unregister(controller) signal.removeEventListener('abort', abort) }) @@ -388,7 +393,7 @@ class Request { } catch {} util.addAbortListener(signal, abort) - requestFinalizer.register(ac, { signal, abort }) + requestFinalizer.register(ac, { signal, abort, controller: ac }) } }