-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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 and different behavior between async-await and Promise #29118
Comments
How can we reproduce? If you have a test case, please try to make it minimal and - strongly preferred - use built-in modules only, no third-party modules. |
@brandonstark: can you try to do a git bisect or go back in versions to figure out when this behaviour changed? Also can you see if you have the same problem with Node 12 (latest)? |
We've been trying, but can't seem to isolate the problem. Any attempt to isolate this code, results in no leak. There is probably some scenario that we don't know how to simulate. We are still trying. If we succeed I will post code that can reproduce the problem. |
Global handles are persistent strong or weak references to an object. Since there's a I can't tell from the info you posted whether you are using them directly or indirectly but I'd start with trying to exclude them first. |
I figured it might be related to async_hooks. We use cls-hooked which uses async_hooks. But disabling it completely did not make any difference. Another theory was that the inspector itself uses async_hooks, or is causing the leak some other way. But with the inspector disabled I still have a leak, though I can't tell what is leaking. |
The leak resulted from our application. It did not resume paused streams on some cases. @brandonstark: Please close this issue. |
I have been trying to debug a memory leak in my code for a very long time.
Running inspect, I can see that the memory that accumulates and is never released is a Promise.
These promises are retained by nothing but "global handles". I can't understand how this promise gets to be held indefinitely by the "global handles".
Note 1. This is not a matter of time. I can wait forever, and the promises are never freed,
Note 2. This is not a problem with axios. This behavior is the same with node-fetch, and request.
There is one function in my code that when I change it from async-await to a new Promise, the behavior is different.
with async-await
with new Promise
The difference
In both cases, using inspect, I see many Promises held only by "global handles".
With the first code, the stuck Promises have PromiseStatus "resolved", and PomiseValue is an IncomingMessage (coming from axios).
With the second code, the stuck Promises have PromiseStatus "pending", and PomiseValue undefined . This causes the leak to be much smaller, because the Promise does not retain the PomiseValue.
This is starting to look like a bug in Node. Can anybody explain the different behavior?
Can anybody explain how a promise gets to be held indefinitely by "global handles"?
Using node v10.15.3.
12 hours with async-await
19 hours with new Promise
The text was updated successfully, but these errors were encountered: