MOD-14618 Fix race condition when calling indexLabelCount on SVS without locks#919
MOD-14618 Fix race condition when calling indexLabelCount on SVS without locks#919
indexLabelCount on SVS without locks#919Conversation
🛡️ Jit Security Scan Results✅ No security findings were detected in this PR
Security scan by Jit
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #919 +/- ##
=======================================
Coverage 96.98% 96.98%
=======================================
Files 129 129
Lines 7567 7574 +7
=======================================
+ Hits 7339 7346 +7
Misses 228 228 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
indexLabelCount on SVS without locks
indexLabelCount on SVS without locksindexLabelCount on SVS without locks
|
|
@alonre24 Reading the index size instead of label count changes the heuristic as it includes marked deleted vectors.
|
|
We can take this fix. |
|
@meiravgri - we can disable |
|
Don’t we already hold the locks when calling this API (through the batch iterator)? |
|
@alonre24 Label count is an internal value in svs. We would need to ask them to change it if we want to take the atomic approach. for hnsw and flat we can change them to be atomic. |
|
@meiravgri we do call |
|
@GuyAv46 Right. i missed that, thanks! |
|
There are two call sites for
Several options were considered for fixing the race in Option A: Lock at the RediSearch call sites. Use the existing Option B: Atomic shadow counters. Maintain Option C: Accept the race, disable SVS bounds check. Decision: We're going with option C. Since |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Fixes a race condition in
VecSimTieredIndex::debugInfoIterator()that can crash when called while background indexing is running.Root Cause
debugInfoIterator()accesses both sub-indexes without holding any locks. For SVS,debugInfoIterator()internally callsindexLabelCount(), which reads internal translation tables. These tables can be concurrently modified by background threads, causing a crash.Fix
Hold the appropriate shared lock when accessing each sub-index's debug info:
flatIndexGuardwhen callingfrontendIndex->debugInfoIterator()mainIndexGuardwhen callingbackendIndex->debugInfoIterator()Each lock is released as soon as the respective iterator is created, minimizing contention.
Follow-up: Once Intel releases a new version of SVS that includes intel/ScalableVectorSearch#301, we need a follow-up PR to upgrade SVS and compile with
SVS_EXPERIMENTAL_CHECK_BOUNDS=OFF.Mark if applicable
Mark if applicable
Note
Low Risk
Low risk concurrency fix that only adds shared-lock guards around
frontendIndex/backendIndexdebug-info access; main concern is potential for minor lock contention in debug/info paths.Overview
Prevents a race when retrieving tiered index debug info during background indexing by acquiring
flatIndexGuardandmainIndexGuard(shared) while callingfrontendIndex->debugInfoIterator()andbackendIndex->debugInfoIterator().Locks are scoped independently per sub-index to keep contention minimal while ensuring thread-safe access to backend SVS debug paths that may touch mutable translation tables.
Written by Cursor Bugbot for commit 56d0b33. This will update automatically on new commits. Configure here.