DeepSeek V4.1 Flash · Balanced
unified-storage-performance-optimizations-grafana-codex
Grafana · Go · S · 30–99 lines · 5 files
The normal review, with one generalist agent. Judge: Claude Haiku 5.5.
- Gold bugs found
- 2 of 3
- Comments published
- 4
- Comments matching a bug
- 2
- Comments not matching
- 2
- Cost of this PR
- $0.129
Published comments (4)
Concurrent cache misses can build duplicate indexes for same key — `getOrCreateIndex` now checks `GetIndex` outside any per-key lock, so two concurrent misses build separate indexes in the same directory and one caller keeps writing to an index already replaced in `b.cache`, making those documents unsearchable. Add per-key deduplication or an in-flight map so only one build per `NamespacedResource` runs at a time.
Logging TotalDocs races with watcher cache writes — The watch goroutine started just above can write the same cache under `cacheMu` while this call reads it, causing a concurrent map read/write panic. Synchronize `TotalDocs` with the cache writer or run it before the watcher starts.
Eager Init leaks watcher on unmanaged in-process servers — In-process servers from `restoptions.go` and `legacy_storage.go` have no `Stop` call site, so each construction starts a broadcaster goroutine and appends a subscriber to `dashboardSqlAccess.subscribers` that is never removed. Keep initialization lazy for servers that are not lifecycle-managed, or trigger shutdown for those construction paths.
Init failure leaks watcher and event-pump goroutines — The discarded instance never gets `Stop`, so the broadcaster and the `backend.WatchWriteEvents` subscription from `initWatcher`, plus the search event pump, keep running against the database forever. Call `s.cancel()` and close the started watchers on the error path before returning.