Repository navigation
A local lab that reproduces the SSR memory leak from a finite gcTime on the server QueryClient #12595
Unanswered
YeonKyuJeon
asked this question in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I ran into a Next.js SSR server whose memory kept growing under load. The cause was a finite
gcTimeon the request-scoped serverQueryClient: each query schedules a removal timer, and the timer keeps the wholeQueryClientalive forgcTimeafter the response is sent.I made a small lab to see it happen: https://github.com/jeonyeonkyu/ssr-query-leak-lab
It runs two production builds of the same app side by side (leak config and fixed config), sends both the same requests, and plots heap usage and the number of
QueryClientinstances that were not collected. In my run with 30 concurrent requests the leak server reached a 768 MB heap limit in about 35 seconds while the fixed one went back to about 33 MB.It can also be pointed at your own two servers with
LAB_LEAK_URLandLAB_FIXED_URL. The lab page is in Korean for now. Feedback on the measurement method is welcome, especially theFinalizationRegistrycounting.All reactions