From 974a85e9d423d0d3505adb39feef15434886f809 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 20 Dec 2023 14:58:55 +0100 Subject: [PATCH] =?UTF-8?q?Call=20fg.unregister()=20after=20a=20dispatcher?= =?UTF-8?q?=20is=20done,=20adds=20UNDICI=5FNO=5FFG=20to=E2=80=A6=20(#2527)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Call fg.unregister() after a dispatcher is done, adds UNDICI_NO_FG to disable finalization Signed-off-by: Matteo Collina * fixup Signed-off-by: Matteo Collina * fixup Signed-off-by: Matteo Collina --------- Signed-off-by: Matteo Collina --- lib/agent.js | 2 ++ lib/core/connect.js | 2 +- test/balanced-pool.js | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/agent.js b/lib/agent.js index 0b18f2a91bd..4ac34d26335 100644 --- a/lib/agent.js +++ b/lib/agent.js @@ -124,6 +124,7 @@ class Agent extends DispatcherBase { const client = ref.deref() /* istanbul ignore else: gc is undeterministic */ if (client) { + this[kFinalizer].unregister(client) closePromises.push(client.close()) } } @@ -137,6 +138,7 @@ class Agent extends DispatcherBase { const client = ref.deref() /* istanbul ignore else: gc is undeterministic */ if (client) { + this[kFinalizer].unregister(client) destroyPromises.push(client.destroy(err)) } } diff --git a/lib/core/connect.js b/lib/core/connect.js index 877956f7bee..2d2521dcfbd 100644 --- a/lib/core/connect.js +++ b/lib/core/connect.js @@ -15,7 +15,7 @@ let tls // include tls conditionally since it is not always available let SessionCache // FIXME: remove workaround when the Node bug is fixed // https://github.com/nodejs/node/issues/49344#issuecomment-1741776308 -if (global.FinalizationRegistry && !process.env.NODE_V8_COVERAGE) { +if (global.FinalizationRegistry && !(process.env.NODE_V8_COVERAGE || process.env.UNDICI_NO_FG)) { SessionCache = class WeakSessionCache { constructor (maxCachedSessions) { this._maxCachedSessions = maxCachedSessions diff --git a/test/balanced-pool.js b/test/balanced-pool.js index 7806652d95b..0e7c1bb169a 100644 --- a/test/balanced-pool.js +++ b/test/balanced-pool.js @@ -437,7 +437,7 @@ const cases = [ expectedRatios: [0.34, 0.34, 0.32], // Skip because the behavior of Node.js has changed - skip: nodeMajor >= 19 + skip: nodeMajor >= 18 }, // 8