fix(fetch): remove abort listener when request settles by ATOM00blue · Pull Request #5318 · nodejs/undici (original) (raw)

@ATOM00blue

fetch() registers an abort listener on the passed AbortSignal (in both the Request constructor and the fetch algorithm) but only removed it via the FinalizationRegistry, i.e. on garbage collection. Reusing a single signal across many requests therefore accumulated listeners and Node.js emitted a MaxListenersExceededWarning.

Capture the listener-removal callbacks and invoke them deterministically once the fetch settles (end-of-body, network error and abort paths) so that no listeners are leaked when a signal is reused.

Closes nodejs#5285

AI review requested due to automatic review settings

May 21, 2026 02:35

tsctx

tsctx

tsctx

tsctx

mcollina

KhafraDev

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})