Skip to content

leak in query garbage collection #2946

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

Closed
TkDodo opened this issue Nov 14, 2021 · 1 comment · Fixed by #2950
Closed

leak in query garbage collection #2946

TkDodo opened this issue Nov 14, 2021 · 1 comment · Fixed by #2950
Labels
bug Something isn't working released

Comments

@TkDodo
Copy link
Collaborator

TkDodo commented Nov 14, 2021

Describe the bug

Queries that should be garbage collected because the cacheTime has elapsed are kept in memory forever if the query was fetching when the last observer was removed.

To Reproduce
https://codesandbox.io/s/youthful-neumann-rh8t6?file=/src/index.js

note:

  • cacheTime is 2 seconds
  • the query takes 5 seconds to fetch
  • it's best to wait until the query has loaded once, then trigger a refetch via window focus and click the button which will unmount the query while the fetch is happening.

Expected behavior
queries to be garbage collected correctly

Additional context

I think the problem is that optionalRemove, once it determines that it has no observers but doesn't remove the query because it's still fetching doesn't restart the timer:

https://github.com/tannerlinsley/react-query/blob/c1ae82ba188fd5abda5e256cac070145e5941447/src/core/query.ts#L216-L220

@tannerlinsley
Copy link
Collaborator

🎉 This issue has been resolved in version 3.33.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants