Explicit gcTime schedules a GC timer during SSR, retaining the whole render in memory
I maintainer di solito rispondono entro 1 giorno
@AdzerKI ci sta già lavorando.
Dal 14/10/2026.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 25/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- node.js, react, typescript
- Ambito
- frontend
Direzione di ricerca
The bug is that an explicit finite gcTime schedules a real timer on the server, while the server default of Infinity does not. Start with the gist's gc-timer-retains-async-context.mjs reproduction and compare pending timers with default and finite. Pull request #12026 already targets this, so review it rather than starting a parallel fix. Done means no garbage-collection timer is scheduled on the server for any gcTime value.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
On the server, a query with an explicit finite gcTime (a regular client-side option) schedules a real setTimeout during SSR. The server default of Infinity is meant to prevent this, but an explicit gcTime bypasses it.
In Node, a pending timer keeps the render's async context (AsyncLocalStorage) alive until it fires. As a result, the entire render stays in memory: the HTML, the RSC payload, and the Request held by react-dom/server.
The timer serves no purpose. The request's QueryClient is discarded together with the response, so there is nothing left to garbage-collect.
Our case: Next.js 16, with a single useQuery({ gcTime: 24h }) in the root provider. Every render left behind a 24-hour timer and about 1.4 MB of retained memory. A heap snapshot of an idle replica showed 272 Request objects and 268 pending timers. Replicas grew until they hit the memory limit and were OOM-killed.
Your minimal, reproducible example
https://gist.github.com/AdzerKI/44081bf1d74a64d43ce651018ce2cba9
Steps to reproduce
- Save gc-timer-retains-async-context.mjs from the gist
- npm i @tanstack/query-core
- node --expose-gc gc-timer-retains-async-context.mjs default
- node --expose-gc gc-timer-retains-async-context.mjs finite
- Compare pendingTimers and rss in the output
Expected behavior
On the server, no garbage-collection timer should be scheduled for any gcTime value, the same as with the server default.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
OS: Linux
Runtime: Node.js 24.21.0 (server-side rendering, no browser involved)
Tanstack Query adapter
react-query
TanStack Query version
v5.104.2
TypeScript version
No response
Additional context
gcTime=default renders=2000 pendingTimers=0 external=2MB rss=119MB
gcTime=60000 renders=2000 pendingTimers=2000 external=1002MB rss=1069MB
- Lingua principale
- TypeScript
- Stelle
- 50.4k
- Fork
- 4.3k
- Merge medio
- 11h 37m
- PR unite (30g)
- 521
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di TanStack/query
-
QueryClient.isFetching and useIsFetching accept a fetchStatus filter and ignore itForse già presa @Apu-Emdad l’ha presa 5 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
solid-query: STRICT_READ_UNTRACKED on Solid 2 — client()/options() read in component body (useMutation, useBaseQuery)Forse di nuovo libera @LeonxLJX l’ha presa 46 giorni fa e non c’è nessuna pull request aperta. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
TanStack/query#11358 · 2 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
solid-query 6.0.0-rc.5: onCacheEvent throws NotReadyError during a Solid 2 (rc.14+) transition landingForse già presa @UzumakiODZ l’ha presa 5 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 28/100
TanStack/query#12031 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
restoreQueries and persisterGc throw on malformed persisted entriesForse già presa @VGontier-cmd l’ha presa 14 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
solid-query: EFFECT_RELAY_TEAR on Solid 2 when a query key changes — useBaseQuery relays the result through a version signal written from a render effectForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
TanStack/query#11903 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di TanStack/query
Issue simili
-
area:workflow bug ready-for-human
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
fil-donadoni/tolaria#6108 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
apache/rocketmq-dashboard#7234 ·
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
vitest-dev/vitest#11656 ·
I maintainer di solito rispondono entro 1 giorno
-
e2e-failure ready-to-code
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
redhat-developer/rhdh-plugin-export-overlays#4460 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
ehmpathy/rhachet-roles-bhrain#655 ·
I maintainer di solito rispondono entro 1 giorno