Two scans of one fresh trace race on the shared .dftindex, so a joined side streams zero rows
PitfallVerified 30 Sep 2026Holds project: dftracer-utils
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.
Symptom#
A joined duql side streams zero rows, or a query fails with gather_units: metadata read failed. It happens when two scans of one fresh (unindexed) trace run together. It is flaky on fresh files and gone after one warm-up query.
Cause#
Three races in the index build:
RocksDBManagerkeyed open handles by the path spelling. On macOS/var/...and/private/var/...gave two opens of one database and a lock error.- A read-write open raced an expired read-write handle that was still closing: "lock hold by current process".
MetadataCollectorUtilityremoved the whole shared.dftindexroot whenneed_rebuild()returned true by mistake. Its read-only open fails while another scan writes.
Fix#
- In the collector: one
AsyncMutexper index root, a per-file cache, and no removal of the root. - In the manager: a per-path count of live writers, and a wait for it.
- Do not canonicalize the
RocksDBManagerkey.test_agg_extensionrelies on a read-only handle and a read-write open of the same database, under two spellings, at the same time. Merging them hits the rule "Cannot upgrade ... while it is still in use".
Evidence#
Observer notes from a dftracer-utils duql joined-subqueries session, 2026-09-30. The first note listed canonical keys as a fix. A later note replaced that part: the macOS /var race was fixed by the collector lock and the live-writer wait.
Also found by searching
- gather_units: metadata read failed; joined duql side streams zero rows on a fresh unindexed trace
- flaky empty join result the first time I query a new trace, fine after one warm-up query
- how do I avoid races when two scans build the same .dftindex at once
- rocksdb lock hold by current process, /var vs /private/var path spelling opens database twice on macOS
- gather_units: metadata read failed
- joined duql side streams zero rows on a fresh trace, fine after a warm-up query
- lock hold by current process rocksdb error macOS /var and /private/var paths
- two scans of the same unindexed trace concurrently, flaky .dftindex race, removed shared directory