Skip to content

Commit 1dfa6c3

Browse files
committed
fix: call explicitly unregister
1 parent c5c6648 commit 1dfa6c3

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/compat/dispatcher-weakref.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class CompatFinalizer {
2828
})
2929
}
3030
}
31+
32+
unregister (key) {}
3133
}
3234

3335
module.exports = function () {

lib/fetch/request.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ const { getMaxListeners, setMaxListeners, getEventListeners, defaultMaxListeners
3535
const kAbortController = Symbol('abortController')
3636

3737
const requestFinalizer = new FinalizationRegistry(({ signal, abort }) => {
38+
// Currently FinalizationRegistry has a problem and will explicitly call unregister.
39+
// https://github.com/nodejs/node/issues/49344
40+
// https://github.com/nodejs/node/issues/47748
41+
// It will be removed in the future.
42+
// Note: The unregister key is abort.
43+
requestFinalizer.unregister(abort)
3844
signal.removeEventListener('abort', abort)
3945
})
4046

@@ -388,7 +394,11 @@ class Request {
388394
} catch {}
389395

390396
util.addAbortListener(signal, abort)
391-
requestFinalizer.register(ac, { signal, abort })
397+
// The third argument must be a registry key to be unregistered.
398+
// Without it, you cannot unregister.
399+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry
400+
// abort is used as the unregister key. ( Because it is unique. )
401+
requestFinalizer.register(ac, { signal, abort }, abort)
392402
}
393403
}
394404

0 commit comments

Comments
 (0)