Skip to content

Commit

Permalink
Call fg.unregister() after a dispatcher is done, adds UNDICI_NO_FG to… (
Browse files Browse the repository at this point in the history
#2527)

* Call fg.unregister() after a dispatcher is done, adds UNDICI_NO_FG to disable finalization

Signed-off-by: Matteo Collina <hello@matteocollina.com>

* fixup

Signed-off-by: Matteo Collina <hello@matteocollina.com>

* fixup

Signed-off-by: Matteo Collina <hello@matteocollina.com>

---------

Signed-off-by: Matteo Collina <hello@matteocollina.com>
  • Loading branch information
mcollina authored Dec 20, 2023
1 parent 871baa7 commit 974a85e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
Expand All @@ -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))
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/core/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/balanced-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 974a85e

Please sign in to comment.