Repository navigation
A local lab that reproduces the SSR memory leak from a finite gcTime on the server QueryClient #12595
Replies: 1 comment
|
Nice lab, running both builds side by side makes the difference really obvious. On the FinalizationRegistry counting: finalizer callbacks aren't guaranteed to run promptly after an object becomes unreachable, so the "not collected" number can include clients that are already garbage but haven't been finalized yet. If you're not doing it already, running with Might also be worth linking #12025 (disabling GC timers on the server) and #12561 (GC timers surviving |
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