Joined-filter window hangs in `drainNoInputContinuations` when a boundary-tie load answers synchronously
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- typescript
- 领域
- backend, databases, testing-qa
调研方向
从查询续接代码中的 drainNoInputContinuations 和 runContinuation 开始,然后检查 joined 加载完成后恢复暂存工作的 joined-filter 门控逻辑。基于 tests/query/joined-filter-sync-tie.test.ts 添加一个回归测试,覆盖同步 tie 加载和异步 joined 加载。完成标准是窗口最终稳定并包含全部 5 行,且测试通过。
由索引模型根据 Issue 内容生成。
描述
On 0.15.2, an ordered, limited window with one LEFT join and a filter on the joined side never settles under this sequence:
- The source answers a page asynchronously, but its boundary-tie load (no limit) synchronously with
true, from rows it already holds. - The joined side answers asynchronously.
drainNoInputContinuations consumes the staged more continuation. runContinuation sees hasPendingJoinedWork() and re-stages the same continuation. Nothing has changed (no graph input, nothing pending), so the while condition still holds and the loop spins synchronously. The joined load can never settle, and the page hangs at 100% CPU.
Repro (plain collections, no custom options): a 30-row items collection left-joined to owners, where(eq(owner.active, true)), orderBy(rank desc), limit(5). items.loadSubset resolves pages after setTimeout and answers limit-less tie loads synchronously. owners.loadSubset resolves after setTimeout. The test below hangs on 0.15.2.
Fix: stop draining when a consumed continuation re-stages itself. The joined work's settlement already resumes it through the joined-filter gate.
const continuation = this.stagedContinuation
this.consumeStagedContinuation()
if (this.stagedContinuation === continuation) break
With it, the repro settles with the full 5-row window, and the full @tanstack/db suite passes. Happy to open a PR.
Repro test (tests/query/joined-filter-sync-tie.test.ts)
import { expect, it } from 'vitest'
import { createCollection } from '../../src/collection/index.js'
import { BTreeIndex } from '../../src/index.js'
import { createLiveQueryCollection } from '../../src/query/live-query-collection.js'
import { eq } from '../../src/query/builder/functions.js'
import { compileSingleRowExpression } from '../../src/query/compiler/evaluators.js'
import type { LoadSubsetOptions } from '../../src/types.js'
type Item = { id: string; rank: number; ownerId: string }
type Owner = { id: string; active: boolean }
it(`settles a joined-filter window whose tie load answers synchronously`, async () => {
const items: Array<Item> = Array.from({ length: 30 }, (_, n) => ({
id: `i${String(n).padStart(2, `0`)}`,
rank: 100 - n,
ownerId: `o${n}`,
}))
const owners: Array<Owner> = items.map((item, n) => ({
id: item.ownerId,
active: n % 3 !== 0,
}))
const delivered = new Set<string>()
const itemCollection = createCollection<Item>({
id: `loop-items`,
getKey: (row) => row.id,
syncMode: `on-demand`,
startSync: true,
autoIndex: `eager`,
defaultIndexType: BTreeIndex,
sync: {
sync: ({ begin, write, commit, markReady }) => {
markReady()
return {
loadSubset: (options: LoadSubsetOptions) => {
const where = options.where
? compileSingleRowExpression(options.where)
: undefined
const from = options.cursor
? compileSingleRowExpression(options.cursor.whereFrom)
: undefined
const offset = from ? 0 : (options.offset ?? 0)
const rows = items
.filter((row) => (where ? where(row) === true : true))
.filter((row) => (from ? from(row) === true : true))
.sort((a, b) => b.rank - a.rank)
.slice(
offset,
options.limit === undefined
? undefined
: offset + options.limit,
)
const answer = () => {
begin()
for (const row of rows) {
if (delivered.has(row.id)) continue
delivered.add(row.id)
write({ type: `insert`, value: { ...row } })
}
return commit()
}
// A page goes over the wire; its boundary ties are rows it holds.
if (options.limit === undefined) return answer()
return new Promise<void>((resolve) =>
setTimeout(() => {
const receipt = answer()
void (receipt === true ? resolve() : receipt.then(resolve))
}, 1),
)
},
}
},
},
})
const ownerCollection = createCollection<Owner>({
id: `loop-owners`,
getKey: (row) => row.id,
syncMode: `on-demand`,
startSync: true,
autoIndex: `eager`,
defaultIndexType: BTreeIndex,
sync: {
sync: ({ begin, write, commit, markReady }) => {
markReady()
return {
loadSubset: (options: LoadSubsetOptions) =>
new Promise<void>((resolve) =>
setTimeout(() => {
const where = options.where
? compileSingleRowExpression(options.where)
: undefined
begin()
for (const row of owners)
if (!where || where(row) === true)
write({ type: `insert`, value: { ...row } })
const receipt = commit()
void (receipt === true ? resolve() : receipt.then(resolve))
}, 1),
),
}
},
},
})
const live = createLiveQueryCollection({
query: (q) =>
q
.from({ item: itemCollection })
.leftJoin({ owner: ownerCollection }, ({ item, owner }) =>
eq(item.ownerId, owner.id),
)
.where(({ owner }) => eq(owner.active, true))
.orderBy(({ item }) => item.rank, `desc`)
.limit(5)
.select(({ item }) => ({ id: item.id })),
})
await live.preload()
await new Promise((resolve) => setTimeout(resolve, 30))
expect(live.size).toBe(5)
await live.cleanup()
})
- 主要语言
- TypeScript
- 星标
- 4k
- 派生
- 277
- 平均合并
- 17 小时 40 分钟
- 30 天内合并 PR
- 223
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
TanStack/db 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
Garbage collection cleans up a collection while one of its transactions is still persisting可能已有人在做 @Nabil372 于 2 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 35/100
维护者通常 1 天内回复
-
persistedCollectionOptions without a schema can't be passed to createCollection (follow-up to #1452)未关闭
难度 3/5 1-2 天 新手友好度 68/100
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 38/100
维护者通常 1 天内回复
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
awslabs/visual-asset-management-system#804 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
restatedev/sdk-typescript#813 ·
-
bug desktop P1 session XS
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
Merit-Systems/x402scan#1312 ·
-
type:bug
难度 2/5 1-3 小时 新手友好度 78/100
Azure/apiops-cli#331 ·
维护者通常 3 天内回复