Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Explicit gcTime schedules a GC timer during SSR, retaining the whole render in memory

未关闭
#12,025 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@AdzerKI 已经在做这个了。

开始于 2026年10月14日。

  • #12026 来自 @AdzerKI —— 未关闭
  • #12053 来自 @mgarcialeniolabs —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
领域
frontend

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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
  1. Save gc-timer-retains-async-context.mjs from the gist
  2. npm i @tanstack/query-core
  3. node --expose-gc gc-timer-retains-async-context.mjs default
  4. node --expose-gc gc-timer-retains-async-context.mjs finite
  5. 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

主要语言
TypeScript
星标
50.4k
派生
4.3k
平均合并
13 小时 35 分钟
30 天内合并 PR
442

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TanStack/query 的其他 Issue

查看 TanStack/query 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。