From 44528c7b488759caf50dfa4bfef897f7391827e6 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 20 Dec 2023 13:04:01 +0100 Subject: [PATCH 1/3] Call fg.unregister() after a dispatcher is done, adds UNDICI_NO_FG to disable finalization Signed-off-by: Matteo Collina --- lib/agent.js | 2 ++ lib/core/connect.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/agent.js b/lib/agent.js index 0b18f2a91bd..3b287570bb9 100644 --- a/lib/agent.js +++ b/lib/agent.js @@ -122,6 +122,7 @@ class Agent extends DispatcherBase { const closePromises = [] for (const ref of this[kClients].values()) { const client = ref.deref() + this[kFinalizer].unregister(client) /* istanbul ignore else: gc is undeterministic */ if (client) { closePromises.push(client.close()) @@ -135,6 +136,7 @@ class Agent extends DispatcherBase { const destroyPromises = [] for (const ref of this[kClients].values()) { const client = ref.deref() + this[kFinalizer].unregister(client) /* istanbul ignore else: gc is undeterministic */ if (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 From 4743b6ebd156809149ccc8e5b7f5ad51bdcac3a4 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 20 Dec 2023 13:06:16 +0100 Subject: [PATCH 2/3] fixup Signed-off-by: Matteo Collina --- lib/agent.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/agent.js b/lib/agent.js index 3b287570bb9..4ac34d26335 100644 --- a/lib/agent.js +++ b/lib/agent.js @@ -122,9 +122,9 @@ class Agent extends DispatcherBase { const closePromises = [] for (const ref of this[kClients].values()) { const client = ref.deref() - this[kFinalizer].unregister(client) /* istanbul ignore else: gc is undeterministic */ if (client) { + this[kFinalizer].unregister(client) closePromises.push(client.close()) } } @@ -136,9 +136,9 @@ class Agent extends DispatcherBase { const destroyPromises = [] for (const ref of this[kClients].values()) { const client = ref.deref() - this[kFinalizer].unregister(client) /* istanbul ignore else: gc is undeterministic */ if (client) { + this[kFinalizer].unregister(client) destroyPromises.push(client.destroy(err)) } } From a5f401e1f01eb83ec2fa695e6ce93f7ab5006e52 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 20 Dec 2023 13:25:49 +0100 Subject: [PATCH 3/3] fixup Signed-off-by: Matteo Collina --- test/balanced-pool.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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