-
-
Notifications
You must be signed in to change notification settings - Fork 935
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
Resource leak when (re-)using an abort signal #2160
Labels
bug
Something does not work as it should
Comments
marcelmeulemans
added a commit
to marcelmeulemans/got
that referenced
this issue
Oct 10, 2022
Not sure that this fix is entirely correct because I may have missed clean up points. Also, needs a test still. Fixes sindresorhus#2160
// @jopemachine |
Lines 254 to 256 in 623229f
this should be this.options.signal?.addEventListener('abort', () => {
this.destroy(new AbortError(this));
}, { once: true }); additionally, we should do this.options.signal?.removeEventListener('abort', abortListener); somewhere in |
jopemachine
added a commit
to jopemachine/got
that referenced
this issue
Oct 10, 2022
4 tasks
1 task
marcelmeulemans
added a commit
to marcelmeulemans/got
that referenced
this issue
Oct 11, 2022
Not sure that this fix is entirely correct because I may have missed clean up points. Also, needs a test still. Fixes sindresorhus#2160
marcelmeulemans
added a commit
to marcelmeulemans/got
that referenced
this issue
Oct 12, 2022
Not sure that this fix is entirely correct because I may have missed clean up points. Also, needs a test still. Fixes sindresorhus#2160
marcelmeulemans
added a commit
to marcelmeulemans/got
that referenced
this issue
Nov 16, 2022
Not sure that this fix is entirely correct because I may have missed clean up points. Also, needs a test still. Fixes sindresorhus#2160
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
When re-using an abort controller for multiple got requests a significant amount of memory is retained by the
AbortSignal
through got. The main reason for this (I think) is that theRequest
instance adds an event listener for theabort
event on the passed signal where the event handler refers back to the request. The event handler is never removed so the signal retains a reference to theRequest
instance for as long as it lives.Actual behavior
The code to reproduce below downloads and discards a 1MB file in a loop. The loop exists when the abort signal is aborted via ctrl-c. The same abort signal is passed to got to cancel the in-progress download. The heap profile screenshot below shows how a large chunk of memory is retained via the callback context of an event listener coming from here:
https://github.com/sindresorhus/got/blob/main/source/core/index.ts#L254
Expected behavior
Memory is released after the request completes.
Code to reproduce
Checklist
Node.jsand Got.The text was updated successfully, but these errors were encountered: