-
Notifications
You must be signed in to change notification settings - Fork 46.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
Context leaks to later renders when render stream destroyed early #14705
Comments
Fix and test case for facebook#14705.
PR to fix: #14706 |
Actually, I've noticed that this bug can also cause one render's context to leak into another later render. This is likely to be more common and more serious than the original effect outlined above. Steps to reproduce:
So data from render 1 leaks to all subsequent renders which access I've added a test for this to PR #14706. That test fails on current master, and I expect this problem also affects v16.7.0. |
Issue also affects Many would say that you should terminate the Node process on an unexpected error, but I imagine a lot of people catch it and send status 500 to the client. |
Just faced the same problem with Request that explodes: <AppContext namespace="root">
<ExplodesHere />
</AppContext> And the second render, of a page that "works": <AppContext namespace="root">
Here I will have two context objects: [{ namespace: 'root' }, { namespace: 'root' }]
</AppContext> |
Thanks @eliseumds for explaining your case, I added a regression test for it. |
Fixed in 16.8.3. |
Do you want to request a feature or report a bug?
Bug.
What is the current behavior?
If a stream created with
.renderToNodeStream()
is destroyed before the render completes, memory can be retained unnecessarily by Contexts which were active at the time.It's not a memory leak per se as memory use is not unbounded. There's a limit on number of threads in use and context slots are reused, so memory use can't increase endlessly.
Would only make a noticeable impact on an application which:
.renderToNodeStream()
or.renderToStaticMarkup()
In the above case, when the spike hits, many threads are created for concurrent renderers. Each thread writes data into a slot of the Contexts it uses. When the threads are destroyed before the renders complete, the Context slots are not cleared, and so left filled with data which is no longer useful, but cannot be freed by GC.
When the spike recedes, this memory continues to be retained.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:
I'll submit a PR with failing test case and fix shorty.
What is the expected behavior?
When stream is destroyed, it should clean up its resources.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
Issue introduced in 961eb65 which is in 16.7.0.
The text was updated successfully, but these errors were encountered: