@@ -35,6 +35,12 @@ const { getMaxListeners, setMaxListeners, getEventListeners, defaultMaxListeners
3535const kAbortController = Symbol ( 'abortController' )
3636
3737const 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
@@ -371,6 +377,17 @@ class Request {
371377 const abort = function ( ) {
372378 const ac = acRef . deref ( )
373379 if ( ac !== undefined ) {
380+ // Currently, there is a problem with FinalizationRegistry.
381+ // https://github.com/nodejs/node/issues/49344
382+ // https://github.com/nodejs/node/issues/47748
383+ // In the case of abort, the first step is to unregister from it.
384+ // If you can refer to it, it is still registered.
385+ // It will be removed in the future.
386+ requestFinalizer . unregister ( abort )
387+ // Unsubscribe a listener.
388+ // FinalizationRegistry will no longer be called, so this must be done.
389+ this . removeEventListener ( 'abort' , abort )
390+
374391 ac . abort ( this . reason )
375392 }
376393 }
@@ -388,7 +405,11 @@ class Request {
388405 } catch { }
389406
390407 util . addAbortListener ( signal , abort )
391- requestFinalizer . register ( ac , { signal, abort } )
408+ // The third argument must be a registry key to be unregistered.
409+ // Without it, you cannot unregister.
410+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry
411+ // abort is used as the unregister key. ( Because it is unique. )
412+ requestFinalizer . register ( ac , { signal, abort } , abort )
392413 }
393414 }
394415
0 commit comments