Repository navigation
[MOD-13616] Use new RETURN-STRICT timeout mechanism in FT.SEARCH coordinator - #8236
Conversation
87d3223 to
e22d557
Compare
Automated performance analysis summaryThis comment was automatically generated given there is performance data available. In summary:
You can check a comparison in detail via the grafana link Performance Improvements - Comparison between master and omerl-search-coord-timeout-return.Time Period from 30 days ago. (environment used: oss-standalone)
Performance Regressions and Issues - Comparison between master and omerl-search-coord-timeout-return.Time Period from 30 days ago. (environment used: oss-standalone)
Tests with No Significant Changes (30 tests)Tests with No Significant Changes
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #8236 +/- ##
==========================================
+ Coverage 82.94% 83.01% +0.06%
==========================================
Files 389 389
Lines 57262 57371 +109
Branches 15567 15567
==========================================
+ Hits 47497 47627 +130
+ Misses 9606 9585 -21
Partials 159 159
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
(cherry picked from commit 479571b)
|
|
||
| // Check if timed out - discard reply and return early. | ||
| // Timeout callback handles the reply, no need to track completion here. | ||
| if (MRCtx_IsTimedOut(ctx)) { |
There was a problem hiding this comment.
When do we free the MRCtx? How do we access it after a timeout?
There was a problem hiding this comment.
Timeout doesn't free MRCtx, only DistSearchFreePrivData callback does that, it happens after the background thread calls unblock client (whether timeout happened or not, if timeout happened, the unblock client is a no-op)
There was a problem hiding this comment.
Ahh right. And we call the unblock API only when all the chunks have been returned?
There may still be some issue here, as you return from this function without increasing the error replies count and calling the reducer (which is where we eventually unblock the client, even if a timeout has occurred)
| // already set, it stays set; if not set, we set it but that's fine since | ||
| // we only call this after SetTimedOut or to check if someone else set it. | ||
| return atomic_flag_test_and_set(&ctx->timedOut); | ||
| } |
There was a problem hiding this comment.
MRCtx_IsTimedOut incorrectly sets flag on read
High Severity
MRCtx_IsTimedOut uses atomic_flag_test_and_set which always sets the flag while returning the previous value. When fanoutCallback calls this function to check if timeout occurred, the first call sets the flag even though no timeout happened. All subsequent calls then return true, causing valid shard replies to be incorrectly discarded. This results in missing search results under normal operation.
Additional Locations (1)
| // If we've received the last reply - unblock the client | ||
| if (ctx->numReplied + ctx->numErrored == ctx->numExpected) { | ||
| if (ctx->fn) { | ||
| if (!timedOut && ctx->fn) { |
There was a problem hiding this comment.
Use-after-free race in fanoutCallback after timeout
High Severity
After the timeout callback (DistSearchTimeoutPartialClient) completes on the main thread, DistSearchFreePrivData frees the MRCtx. However, the IO thread's fanoutCallback may still receive pending shard replies and attempt to access the freed MRCtx via the privdata pointer. This includes calling MRCtx_IsTimedOut(ctx), incrementing ctx->numErrored, and accessing ctx->bc. This is a use-after-free race condition that can cause crashes or memory corruption.
Additional Locations (1)
| bool MRCtx_TryClaimReducing(struct MRCtx *ctx) { | ||
| bool expected = false; | ||
| return atomic_compare_exchange_strong(&ctx->reducing, &expected, true); | ||
| } |
There was a problem hiding this comment.
Consider using atomic_flag for this logic, as it feels appropriate



Partial Results Timeout for FT.SEARCH Coordinator
Summary
Implements partial results timeout support for the FT.SEARCH coordinator when
ON_TIMEOUTpolicy is set toreturn-strict. Previously, the coordinator only supported thefailtimeout policy. Now, when a timeout occurs, the coordinator returns partial results from shards that have already responded, along with a timeout warning.Changes
Timeout Handling (
src/module.c,src/module.h)searchRequestCtxstruct to hold parsed search request parameters on the main thread before blockingON_TIMEOUT=return-stricttimedOutandreducingflags for thread-safe coordination between timeout callback and coordinator threadMapReduce Context (
src/coord/rmr/rmr.c,src/coord/rmr/rmr.h)MRCtx_SetTimedOut()andMRCtx_IsTimedOut()for atomic timeout flagMRCtx_SetReducing()for claiming exclusive reducing stateTests (
tests/pytests/test_blocked_client_timeout.py)FT.SEARCHandFT.PROFILEcommandsTimeout Behavior
Mark if applicable
Release Notes
If a release note is required (bug fix / new feature / enhancement), describe the user impact of this PR in the title.
Note
Medium Risk
Touches coordinator blocked-client timeout handling, fanout reply collection, and reducer/unblock synchronization using atomics/conds, which is concurrency-sensitive and could affect query completion paths under load/timeouts.
Overview
Adds partial-results timeout support for coordinator
FT.SEARCHwhenON_TIMEOUT=return-strict, replying with whatever shard results have arrived plus a timeout warning instead of failing.To support this, distributed search now parses/allocates
searchRequestCtxandMRCtxon the main thread before blocking, adds timeout/reducing state + synchronization toMRCtx, discards late fanout replies after timeout, and updates the reducer/bailout paths to avoid double-reduce/double-unblock races.Also refactors
FT.SEARCHargument parsing to a single-passArgsCursor/ACArgSpecflow (and buildsrequiredFieldsthere), extends empty-reply handling to emit timeout warnings, adds debug-only coordinator reduce pause commands (ENABLE_ASSERT), and expands Python tests to cover return-strict partial results, no-reply timeouts, and timeout-during-reduce scenarios (plus warning shape change to arrays).Written by Cursor Bugbot for commit e5b01ca. This will update automatically on new commits. Configure here.