@@ -371,6 +371,18 @@ class Request {
371
371
const abort = function ( ) {
372
372
const ac = acRef . deref ( )
373
373
if ( ac !== undefined ) {
374
+ // Currently, there is a problem with FinalizationRegistry.
375
+ // https://github.com/nodejs/node/issues/49344
376
+ // https://github.com/nodejs/node/issues/47748
377
+ // In the case of abort, the first step is to unregister from it.
378
+ // If the controller can refer to it, it is still registered.
379
+ // It will be removed in the future.
380
+ requestFinalizer . unregister ( abort )
381
+
382
+ // Unsubscribe a listener.
383
+ // FinalizationRegistry will no longer be called, so this must be done.
384
+ this . removeEventListener ( 'abort' , abort )
385
+
374
386
ac . abort ( this . reason )
375
387
}
376
388
}
@@ -388,7 +400,11 @@ class Request {
388
400
} catch { }
389
401
390
402
util . addAbortListener ( signal , abort )
391
- requestFinalizer . register ( ac , { signal, abort } )
403
+ // The third argument must be a registry key to be unregistered.
404
+ // Without it, you cannot unregister.
405
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry
406
+ // abort is used as the unregister key. (because it is unique)
407
+ requestFinalizer . register ( ac , { signal, abort } , abort )
392
408
}
393
409
}
394
410
0 commit comments