-
Notifications
You must be signed in to change notification settings - Fork 539
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
Memory leak when aborting fetch requests #2198
Comments
looks like we are not clearing up resources in case of an abort |
Does the same happens for
|
cc @ronag |
@metcoder95 I'm sorry, I don't know. I have never used |
No worries! But I was referring to |
Yes, as @KhafraDev mentioned it is basically It is because of pendingUnhandledRejections keeping references on the promises, so that node can remove it it later from the WeakMap. |
Can or should we even implement a solution in undici? |
Can - yes (?), as your PR did that. Should - yes, we can always revert the change once it's fixed upstream. We've implemented plenty of workarounds for bugs in node core in the past. |
This is a bug, which needs to be fixed in node core, as it is a "bug" in the event loop. This bug is basically introduced by the logic which handles the unhandledPromiseRejected warning. Basically this line results in this issue: So because we keep a reference to the promise for "at least one tick" v8 can not garbage collect the promise. So what happens is that before the event loop can go to the "next" iteration, it gets another promise to handle and starts again processing the same iteration of the event loop as processPromiseRejections returns true. |
The previous promises should be collectable, no? Why is it staying alive? If that's the case you should be able to reproduce it just with an abortcontroller or a self-rejecting promise chain. |
Exactly. You dont need fetch. You can use the example in the corresponding node issue nodejs/node#43655 |
Then, we close this. |
Bug Description
A memory leak occurs when frequently aborting fetch requests.
Reproducible By
Run the following code in Node.js.
In less than a minute, I see memory usage of the Node.js process climb to several gigabytes.
Expected Behavior
Memory usage to remain stable, as is the case when you comment out the
controller.abort();
statement.Environment
The text was updated successfully, but these errors were encountered: