-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
fix(gatsby): leak less in chokidar listeners #27685
Conversation
…ar/fix-memory-leak
@@ -87,8 +85,8 @@ exports.sourceNodes = ({ createContentDigest, actions, store }) => { | |||
siteMetadata: { | |||
...configCopy.siteMetadata, | |||
}, | |||
port: state.program.proxyPort, | |||
host: state.program.host, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we retain the state
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, we could call store.getState()
here, but because program
can't change this is fine (program
does get retained in memory either way)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, let's ship it!
Published in |
Description
This PR addresses one of our memory leaks in
develop
with refresh endpoint (in this case in internal plugininternal-data-bridge
).Refresh endpoint always re-runs
sourceNodes
and we keep re-creating chokidar listeners that retain current redux state at the moment of thesourceNodes
call. So we basically retain as many state "snapshots" as there weresourceNode
API calls (i.e. refreshes).To confirm I've run the https://github.com/reactjs/reactjs.org website with a 200MB node memory limit and kept hitting the
__refresh
endpoint. Before this PR it was OOMing on the 14-16th refresh, after this PR somewhere after 30th (so other memory leaks in play)To clarify: this is not the only leak 😢 We have others. It is possible that chokidar listeners in
gatsby-source-filesystem
are also leaking. But this warrants a separate investigation.Also, originally we were hoping that sourceNodesStatefully (#19663) would be a proper fix for those kinds of leaks but it has it's own issues and breaking changes, so need to fix those individually.
Related Issues
Partially addresses #25868