router-ssr-query-core: reader.releaseLock() can deadlock WebKit's GC after hydration
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 停滞
- 技術スタック
- playwright, react, typescript
調査の方向性
Start at packages/router-ssr-query-core/src/index.ts, especially the reader cleanup around lines 244–260, and review the standalone WebKit reproducer in the issue. Check how the stream reader is used after the loop and run the reproducer with Playwright WebKit on Linux. Done means hydration no longer freezes and the reproducer completes without a freeze; linked PR #8796 is already open.
索引モデルが issue の本文から書いたものです。
説明
Which project does this relate to?
Start
Describe the bug
In Playwright's WebKit on Linux, a page using @tanstack/react-router-ssr-query can freeze for good right after load. The main thread never comes back.
Stall dumps put the WebKit web process main thread in a garbage collection, waiting on a lock nobody else holds:
Heap::collectInMutatorThread
-> marking constraint
-> JSReadableStreamDefaultReaderOwner::isReachableFromOpaqueRoots
-> Lock::lockSlow
WebKit's native ReadableStreamDefaultReader.releaseLock() runs stream JavaScript while it holds the reader's lock. If a GC starts there, the marking constraint tries to take the same lock and the page deadlocks.
router-ssr-query-core calls reader.releaseLock() in a finally when the dehydrated query stream ends, which is just after load:
Numbers:
- Bare-page probe in Playwright's WebKit (script below): 7 of 120 rounds froze with
releaseLock(), 0 of 120 without it. - Our app's Playwright suite: 3 fixture timeouts in 400 walks before patching, 0 in 1,200 walks after dropping the
releaseLock()call.
I don't know whether Safari itself is affected. I have only seen it in Playwright's WebKit build on Linux.
Complete minimal reproducer
No app reproducer. The standalone script below reproduces the WebKit side without TanStack. It does what router-ssr-query-core does (read a stream to the end, then releaseLock()) under allocation pressure.
webkit-release-lock.ts (Linux, node webkit-release-lock.ts, Node 24, @playwright/test 1.62.0)
import { webkit } from '@playwright/test'
const RELEASED_ROUND_LIMIT = 360
const DROPPED_ROUND_COUNT = 120
const STREAMS_PER_ROUND = 200
const ROUND_DEADLINE_MS = 20_000
const browser = await webkit.launch()
let releasedWalk: RoundWalk
let droppedWalk: RoundWalk
try {
releasedWalk = await walkRounds('released')
droppedWalk = await walkRounds('dropped')
} finally {
await browser.close()
}
console.table({ 'reader released': releasedWalk, 'reader dropped': droppedWalk })
console.log(JSON.stringify({ webkit: browser.version(), arch: process.arch }))
if (releasedWalk.frozenRoundCount === 0 || droppedWalk.frozenRoundCount > 0) process.exitCode = 1
type ReaderEnd = 'released' | 'dropped'
type RoundWalk = { roundCount: number; frozenRoundCount: number }
async function walkRounds(readerEnd: ReaderEnd): Promise<RoundWalk> {
const roundLimit = readerEnd === 'released' ? RELEASED_ROUND_LIMIT : DROPPED_ROUND_COUNT
let frozenRoundCount = 0
for (let roundNumber = 1; roundNumber <= roundLimit; roundNumber++) {
const roundContext = await browser.newContext()
try {
const probePage = await roundContext.newPage()
await probePage.goto('data:text/html,<p>release-lock probe</p>')
const isFrozen = await Promise.race([
probePage
.evaluate(readStreamsUnderCollection, { readerEnd, streamCount: STREAMS_PER_ROUND })
.then(() => false),
new Promise<boolean>((resolve) => setTimeout(() => resolve(true), ROUND_DEADLINE_MS)),
])
if (isFrozen) frozenRoundCount++
} finally {
await roundContext.close().catch(() => {})
}
if (readerEnd === 'released' && frozenRoundCount > 0)
return { roundCount: roundNumber, frozenRoundCount }
}
return { roundCount: roundLimit, frozenRoundCount }
}
async function readStreamsUnderCollection({
readerEnd,
streamCount,
}: {
readerEnd: ReaderEnd
streamCount: number
}) {
let garbageObjects: Array<{ index: number; pair: number[]; text: string }> = []
function allocateGarbage(objectCount: number) {
for (let objectIndex = 0; objectIndex < objectCount; objectIndex++)
garbageObjects.push({
index: objectIndex,
pair: [objectIndex, objectIndex + 1],
text: `g${objectIndex}${Math.random()}`,
})
if (garbageObjects.length > 300_000) garbageObjects = []
}
async function drainChunks(chunkReader: ReadableStreamDefaultReader<{ chunk: number }>) {
try {
for (;;) {
const { done } = await chunkReader.read()
if (done) return
allocateGarbage(500)
}
} finally {
if (readerEnd === 'released') chunkReader.releaseLock()
}
}
const allocationTimer = setInterval(() => allocateGarbage(20_000), 1)
try {
for (let streamIndex = 0; streamIndex < streamCount; streamIndex++) {
let streamController: ReadableStreamDefaultController<{ chunk: number }> | undefined
const chunkStream = new ReadableStream<{ chunk: number }>({
start(controller) {
streamController = controller
},
})
const chunkDrain = drainChunks(chunkStream.getReader())
for (let chunkIndex = 0; chunkIndex < 10; chunkIndex++) {
streamController?.enqueue({ chunk: chunkIndex })
if (chunkIndex % 3 === 0) await new Promise((resolve) => setTimeout(resolve, 0))
}
streamController?.close()
await chunkDrain
}
} finally {
clearInterval(allocationTimer)
}
}
Steps to Reproduce the Bug
- On Linux, install
@playwright/test1.62.0 and its WebKit (npx playwright install webkit). - Run
node webkit-release-lock.ts. - The "reader released" walk freezes a round (20 s deadline) within a few hundred rounds. The "reader dropped" walk never freezes.
Expected behavior
Hydration finishes and the page stays responsive. Instead, the page sometimes freezes for good right after load.
Platform
@tanstack/router-ssr-query-core1.169.3 (via@tanstack/react-router-ssr-query1.167.3,@tanstack/react-start1.169.2,@tanstack/react-router1.170.44)- OS: Linux (GitHub Actions runners)
- Browser: Playwright WebKit from
@playwright/test1.62.0 - Bundler: Vite 8.2.4
Additional context
Proposed fix: drop the finally { reader.releaseLock() }. Once the loop exits the stream has ended (or the reader has been cancelled), and nothing else reads it, so the lock does not need releasing. We ship this as a pnpm patch and will open a PR.
The WebKit deadlock itself is a WebKit bug. Removing the call avoids it until WebKit fixes it.
Drafted with AI assistance.
- 主要言語
- TypeScript
- スター
- 15.3k
- フォーク
- 1.9k
- 平均マージ
- 1日 5時間
- マージ済み PR(30日)
- 46
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
TanStack/router のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
Masked navigation drops the first character of the hash each time (__tempLocation hash missing '#')対応中かも @hassanabrar202 が 8 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
router-generator: lazy-load Prettier (costs ~300–450ms per build even when formatting is off)対応中かも @Sheraff が 27 日前に担当しました。 オープンpackage: router-generator performance
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
router-generator: sibling `physical()` subtrees in a virtual route config generate duplicate identifiers対応中かも @Sheraff が 27 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
docs(router): clarify static title fallback in SPA mode対応中かも @Rohan-Dedhia が 17 日前に担当しました。 オープン
難易度 1/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
TanStack/router の issue をすべて見る
似ている issue
-
[BUG]: Shared links drop the configured basePath on GitHub Pages対応中かも @anshulchikhale30-p が今日担当しました。 オープンbug
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
StabilityNexus/IdentityTokens-EVM-Frontend#182 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Add: GTrekkerオープンcheck:passed streams:add
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
Koenkk/zigbee-herdsman-converters#13900 ·
メンテナーはふだん 1 日以内に返信
-
area: ui Bug Payload OSS
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
payloadcms/payload#19839 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
jeanibarz/knowledge-base-mcp-server#1291 ·
メンテナーはふだん 1 日以内に返信