Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged

Conversation

achingbrain
Copy link
Member

@achingbrain achingbrain commented Apr 22, 2024

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 nodejs/undici#3157 for more information.

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

@achingbrain achingbrain requested a review from a team as a code owner April 22, 2024 12:26
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 `MaxListenersExceededWarning`s 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.

See https://github.com/nodejs/node/issues/52635 for more information.
@achingbrain achingbrain force-pushed the fix/maxlistenersexceededwarning-in-http-blockbroker branch from 1d3a4f9 to e146dc3 Compare April 22, 2024 12:27
@achingbrain achingbrain merged commit 5e98950 into main Apr 22, 2024
19 checks passed
@achingbrain achingbrain deleted the fix/maxlistenersexceededwarning-in-http-blockbroker branch April 22, 2024 16:09
@achingbrain achingbrain mentioned this pull request Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants