Skip to content

Commit 048f92d

Browse files
mcollinacrysmags
authored andcommitted
Call fg.unregister() after a dispatcher is done, adds UNDICI_NO_FG to… (nodejs#2527)
* Call fg.unregister() after a dispatcher is done, adds UNDICI_NO_FG to disable finalization Signed-off-by: Matteo Collina <[email protected]> * fixup Signed-off-by: Matteo Collina <[email protected]> * fixup Signed-off-by: Matteo Collina <[email protected]> --------- Signed-off-by: Matteo Collina <[email protected]>
1 parent 908459a commit 048f92d

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

lib/agent.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class Agent extends DispatcherBase {
124124
const client = ref.deref()
125125
/* istanbul ignore else: gc is undeterministic */
126126
if (client) {
127+
this[kFinalizer].unregister(client)
127128
closePromises.push(client.close())
128129
}
129130
}
@@ -137,6 +138,7 @@ class Agent extends DispatcherBase {
137138
const client = ref.deref()
138139
/* istanbul ignore else: gc is undeterministic */
139140
if (client) {
141+
this[kFinalizer].unregister(client)
140142
destroyPromises.push(client.destroy(err))
141143
}
142144
}

lib/core/connect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let tls // include tls conditionally since it is not always available
1515
let SessionCache
1616
// FIXME: remove workaround when the Node bug is fixed
1717
// https://github.com/nodejs/node/issues/49344#issuecomment-1741776308
18-
if (global.FinalizationRegistry && !process.env.NODE_V8_COVERAGE) {
18+
if (global.FinalizationRegistry && !(process.env.NODE_V8_COVERAGE || process.env.UNDICI_NO_FG)) {
1919
SessionCache = class WeakSessionCache {
2020
constructor (maxCachedSessions) {
2121
this._maxCachedSessions = maxCachedSessions

test/balanced-pool.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ const cases = [
437437
expectedRatios: [0.34, 0.34, 0.32],
438438

439439
// Skip because the behavior of Node.js has changed
440-
skip: nodeMajor >= 19
440+
skip: nodeMajor >= 18
441441
},
442442

443443
// 8

0 commit comments

Comments
 (0)