CleanupQueue schedules GC deadlines on wall-clock time but services them with an elapsed-time timer
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 78/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- typescript
- Ambito
- performance
Direzione di ricerca
Inizia da packages/db/src/collection/cleanup-queue.ts e segui schedule, updateTimeout e process. Riproduci lo scenario di avanzamento dell’orologio con l’esempio deterministico fornito, quindi verifica che le scadenze e la gestione dei timer utilizzino lo stesso orologio del tempo trascorso. Il lavoro è completato quando la pulizia viene eseguita dopo gcTime nonostante Date.now() vada indietro e il comportamento pertinente di Vitest abbia esito positivo.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
CleanupQueue schedules GC deadlines on wall-clock time but services them with an elapsed-time timer
Package: @tanstack/db 0.8.7 — packages/db/src/collection/cleanup-queue.ts (unchanged on main at the time of writing).
What happens
CleanupQueue.schedule records executeAt = Date.now() + gcTime. updateTimeout arms setTimeout(process, executeAt - Date.now()), and process runs a task only when Date.now() >= task.executeAt, otherwise re-arming for the remainder.
setTimeout measures elapsed time; Date.now() is the realtime clock. When realtime moves backwards between schedule and process — an NTP step, a VM or container guest resynchronising with its host, a manual clock change — process finds now < executeAt and re-arms for executeAt - now, which is roughly the size of the step. Every pending cleanup is delayed by that amount regardless of its gcTime.
For a live query collection this delays the release of its subscriptions to its source collections: a component unmounts, the live query's gcTime (1 ms under @tanstack/react-db's useLiveQuery) elapses, and the source still counts it as a subscriber seconds later.
How it was observed
In a Vitest lane that waits for source collections to reach zero subscribers before disposing them, the wait timed out intermittently with the queue holding one task whose executeAt was 1.7–2.7 s ahead of Date.now() and its timer armed for that difference. A sampler on the same machine (a WSL2 guest with an in-guest time-sync service) recorded the realtime clock stepping back ~3.7 s periodically while performance.now() advanced steadily. The environment is only how it was noticed; any realtime step reproduces it.
Deterministic reproduction
import { createCollection, createLiveQueryCollection } from '@tanstack/db'
const source = createCollection<{ id: string }>({
id: 'source',
getKey: (row) => row.id,
startSync: true,
sync: { sync: ({ markReady }) => { markReady(); return () => {} } },
})
const live = createLiveQueryCollection({
query: (q) => q.from({ s: source }),
gcTime: 1,
startSync: true,
})
const subscription = live.subscribeChanges(() => {})
console.log(source.subscriberCount) // 1
subscription.unsubscribe() // live query's GC is scheduled: executeAt = Date.now() + 1
const realNow = Date.now
Date.now = () => realNow() - 3000 // realtime steps back 3 s before the timer fires
setTimeout(() => console.log(source.subscriberCount), 100) // still 1
setTimeout(() => console.log(source.subscriberCount), 3500) // 0 — released ~3 s late
With a monotonic deadline the second log would already read 0 at 100 ms.
Suggested property
Deadlines and the timer that services them should share a clock: compute executeAt from a monotonic elapsed-time source (for example performance.now(), with Date.now() only as a fallback where it is unavailable) so that a realtime step cannot move a scheduled cleanup. The specific implementation is up to you; the property is that process runs a task once the elapsed time since schedule reaches gcTime.
- Lingua principale
- TypeScript
- Stelle
- 3.9k
- Fork
- 272
- Merge medio
- 1g 1h
- PR unite (30g)
- 222
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di TanStack/db
-
Electric progressive: apply and confirm changes to visible rows during the background full syncAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 38/100
I maintainer di solito rispondono entro 1 giorno
-
Extend the Effect skipInitial oracle lane: ordered windows, includes, failures, and ordinary EffectsAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
I maintainer di solito rispondono entro 1 giorno
-
Progressive collection live queries remain suspended after their requested subset finishes loadingForse già presa @KyleAMathews l’ha presa oggi. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 5/100
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
-
area:cowork area:desktop documentation enhancement platform:macos
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
anthropics/claude-code#101720 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
apache/rocketmq-dashboard#6610 ·
I maintainer di solito rispondono entro 3 giorni
-
Add: MS NOWApertacheck:passed streams:add
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
Global update drops overrideAccess, so Local API updateGlobal fails filterOptions validation (3.90 regression)Forse già presa @PINYOPATTANAWASANPORN l’ha presa oggi. Apertaarea: core Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
payloadcms/payload#18674 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno