Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Joined-filter window hangs in `drainNoInputContinuations` when a boundary-tie load answers synchronously

オープン 初心者向け
#2,241 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript

調査の方向性

クエリ継続処理の drainNoInputContinuations と runContinuation から始め、joined の読み込みが完了した後にステージングされた処理を再開する joined-filter ゲートを確認してください。同期的な tie の読み込みと非同期の joined の読み込みを対象に、tests/query/joined-filter-sync-tie.test.ts に基づく回帰テストを追加してください。ウィンドウが 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:

  1. The source answers a page asynchronously, but its boundary-tie load (no limit) synchronously with true, from rows it already holds.
  2. 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
スター
3.9k
フォーク
277
平均マージ
18時間 7分
マージ済み PR(30日)
228

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

TanStack/db のほかの issue

TanStack/db の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。