ipfs / helia

An implementation of IPFS in JavaScript
https://helia.io
Other
812 stars 81 forks source link

fix: use a short-lived AbortSignal for fetch operations #511

Closed achingbrain closed 2 months ago

achingbrain commented 2 months ago

Node's undici module appears to be adding listeners for the "abort" event on any passed AbortSignal but then not cleaning them up.

This casues many MaxListenersExceededWarnings to appear in the console and likely causes a memory leak.

To work around this, use a short-lived AbortSignal for each request that can be garbage collected along with the request itself and trigger "abort" on it if the long-lived signal aborts, taking care to remove any added listeners once we are done with the request.

See https://github.com/nodejs/undici/issues/3157 for more information.

Change checklist