Explicit gcTime schedules a GC timer during SSR, retaining the whole render in memory
メンテナーはふだん 1 日以内に返信
@AdzerKI がすでに取り組んでいます。
2026年10月14日 から。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 25/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- node.js, react, typescript
- 領域
- 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
- 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
- 主要言語
- TypeScript
- スター
- 50.4k
- フォーク
- 4.3k
- 平均マージ
- 13時間 35分
- マージ済み PR(30日)
- 442
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
TanStack/query のほかの issue
-
QueryClient.isFetching and useIsFetching accept a fetchStatus filter and ignore it対応中かも @Apu-Emdad が 3 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
solid-query: STRICT_READ_UNTRACKED on Solid 2 — client()/options() read in component body (useMutation, useBaseQuery)再び着手できるかも @LeonxLJX が 44 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
TanStack/query#11358 · コメント 2 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
solid-query 6.0.0-rc.5: onCacheEvent throws NotReadyError during a Solid 2 (rc.14+) transition landing対応中かも @UzumakiODZ が 2 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 28/100
TanStack/query#12031 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
restoreQueries and persisterGc throw on malformed persisted entries対応中かも @VGontier-cmd が 12 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
TanStack/query#11903 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
chrisparsons83/flexspotff#215 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
vitest-dev/vitest#11633 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信