Persisted Query Collection can enter error state when refetch supersedes a pending SQLite application
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 48/100
- Tipo de issue
- Bug
- Clareza
- Razoavelmente clara
- Status de atividade
- Ativa
- Stack de tecnologia
- sqlite, typescript
- Domínio
- databases, testing-qa
Direção de pesquisa
Start by tracing enqueueResultApplication, invalidatePendingResultApplication, and trackResultApplication through the persisted Query Collection and sync transaction code. Reproduce the interleaving with the described node:sqlite integration test, focusing on the result of commit(signal) and pending SQLite application. Done means the second refetch exposes value 3 without an application error or a stale value 1.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Versions
@tanstack/db0.11.1@tanstack/query-db-collection1.3.2@tanstack/expo-db-sqlite-persistence0.2.26@tanstack/react-db0.5.1
Problem
A second refetch of a persisted Query Collection can leave an active collection in error when the previous query result has already committed a sync transaction but SQLite has not applied it yet. This happens during ordinary use, without cleanup or a session change.
The adapter logs:
[QueryCollection] Error applying query overlap: AbortError: Sync transaction was aborted before application
[Live Query Error] Source collection 'overlap' entered error state
The collection can retain the old row after both refetches settle.
Deterministic reproduction
- Create a persisted Query Collection with one row
{ id: 'row', value: 1 }, a QueryClient, and an Expo-SQLite-compatible database. Preload it. - Decorate the database
runAsyncto await a deferred promise when aholdWritesflag is set. This delays SQLite application without delayingqueryFn. - Set
holdWrites = true, change the server row to{ id: 'row', value: 2 }, and callcollection.utils.refetch(). - Wait until the query fetch is idle and its result has started applying to SQLite (the decorated
runAsynchas entered the wait). - Change the server row to
{ id: 'row', value: 3 }and callcollection.utils.refetch()again. - Release the SQLite write; await both refetches.
Expected: value 3 is visible; no collection application error.
Actual: an AbortError is logged by trackResultApplication, and the visible row can remain value 1. The second query function did run, so this is not a fetch deduplication issue.
This also occurs when a mutation handler publishes an authoritative server row with writeUpsert while a query refresh is in flight, as in our XP award collection.
Likely cause
enqueueResultApplication calls invalidatePendingResultApplication for the previous result. That unconditionally aborts its controller. When its sync transaction has already been committed and is waiting for SQLite, aborting it removes it from the core pending queue. The newer transaction for the same row can depend on that queued transaction and gets invalidated too (SyncTransactionAbortedError).
I reproduced this in a real node:sqlite integration test. Keeping committed sync transactions alive until their SQLite application finishes, while still aborting pre-commit work, makes the test pass. A guard around cancellation after commit(signal) returns a pending application receipt is one possible fix. This is a suggested direction, not a claim that it covers all interleavings.
- Linguagem predominante
- TypeScript
- Estrelas
- 3.9k
- Forks
- 268
- Merge médio
- 1d 4h
- PRs com merge (30d)
- 178
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de TanStack/db
-
Persisted on-demand Electric collection enters error after a committed transaction waits across subset hydrationTalvez já em andamento @alec-watts assumiu hoje. Aberta
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 45/100
TanStack/db#2036 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
SQLite persistence silently serializes Temporal values as {}, breaking hydration and subset queriesTalvez já em andamento @KyleAMathews assumiu hoje. Aberta
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 50/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 30/100
Mantenedores costumam responder em até 1 dia
-
useLiveInfiniteQuery commits an empty first render over a synchronously loaded collection (useLiveQuery doesn't)Talvez já em andamento @KyleAMathews assumiu há 1 dia. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 48/100
TanStack/db#1972 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
Todas as issues de TanStack/db
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
umbraco/Umbraco-CMS-MCP-Dev#512 ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
wimpysworld/sidra#290 ·
Mantenedores costumam responder em até 1 dia
-
defuFn invokes function values for inherited default propertiesTalvez já em andamento @xiehuanyi assumiu hoje. Aberta
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 85/100
-
feature request good first issue
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
TabularisDB/tabularis#853 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 Menos de uma hora Facilidade para iniciantes 85/100
capricorn86/happy-dom#2474 ·
Mantenedores costumam responder em até 2 dias