Explicit gcTime schedules a GC timer during SSR, retaining the whole render in memory
Maintainer thường phản hồi trong vòng 1 ngày
@AdzerKI đang làm issue này rồi.
Từ ngày 14/10/2026.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- node.js, react, typescript
- Lĩnh vực
- frontend
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- TypeScript
- Star
- 50.4k
- Fork
- 4.3k
- Merge trung bình
- 12 giờ 18 phút
- Pull request đã merge (30 ngày)
- 488
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của TanStack/query
-
QueryClient.isFetching and useIsFetching accept a fetchStatus filter and ignore itCó thể đã có người làm @Apu-Emdad đã nhận 5 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
solid-query: STRICT_READ_UNTRACKED on Solid 2 — client()/options() read in component body (useMutation, useBaseQuery)Có thể làm lại được @LeonxLJX đã nhận 45 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
TanStack/query#11358 · 2 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
solid-query 6.0.0-rc.5: onCacheEvent throws NotReadyError during a Solid 2 (rc.14+) transition landingCó thể đã có người làm @UzumakiODZ đã nhận 4 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 28/100
TanStack/query#12031 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
restoreQueries and persisterGc throw on malformed persisted entriesCó thể đã có người làm @VGontier-cmd đã nhận 13 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
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 effectCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
TanStack/query#11903 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của TanStack/query
Issue tương tự
-
[测试] 等待仓库加载后再记录多仓库排序基线Có thể đã có người làm @myot233 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area:arcade p3-medium ready-for-agent testing type:docs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
fderuiter/deruiter.dev#2369 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area:devenv origin:agent type:bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
overengineeringstudio/effect-utils#1949 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
ccch1mneyyy/dsh-TUI#1631 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
MiniMax-AI/minimax-code#507 ·
Maintainer thường phản hồi trong vòng 1 ngày