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

Prevent RenderPromises memory leak by calling renderPromises.clear() after getMarkupFromTree finishes. #7943

Merged
merged 4 commits into from
Apr 5, 2021

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Apr 2, 2021

This test is my best guess at a reproduction of issue #7942, given the heap snapshots provided by @AlexMost.

As with any FinalizationRegistry-driven test, the details are tricky, but you can see from the history of this PR that calling renderPromises.clear() makes the failing test pass consistently.

This is my best guess at a reproduction of issue #7942, given the heap
snapshot traces provided by @AlexMost.
Should fix #7942 and the tests I added in my previous commit.
@benjamn benjamn changed the title Failing test of RenderPromises QueryInfo garbage collection. Prevent RenderPromises memory leak by calling renderPromises.clear() after getMarkupFromTree finishes. Apr 2, 2021
@benjamn benjamn marked this pull request as ready for review April 2, 2021 18:50
Comment on lines +55 to +56
}).finally(() => {
renderPromises.clear();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We sometimes get complaints about using Promise.prototype.finally from folks who aren't using a polyfill in older browsers, but I think it's fine to use it here, because this is server-side rendering code, which typically runs in Node.js, which has supported Promise.prototype.finally since v8.1.4.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could always use try/finally and async/await too :)

Copy link
Member

@hwillson hwillson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great fix - thanks @benjamn!

@benjamn benjamn merged commit 0b1b8e7 into main Apr 5, 2021
@benjamn benjamn deleted the 7942-RenderPromises-memory-leak branch April 5, 2021 15:08
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants