Repository navigation
[MOD-14074] Shard-level FAIL timeout for FT.HYBRID - #8657
Conversation
🛡️ Jit Security Scan Results✅ No security findings were detected in this PR
Security scan by Jit
|
3b9e23e to
8b60161
Compare
8b60161 to
ee38fe4
Compare
| replyWithCursors(ctx, req->cursors); | ||
| array_free(req->cursors); | ||
| req->cursors = NULL; | ||
| return REDISMODULE_OK; |
There was a problem hiding this comment.
Reply callback crashes on NULL cursors after timeout
High Severity
HybridQueryCursorReplyCallback accesses req->cursors without checking for NULL or whether timeout already occurred. If HybridQueryTimeoutFailCallback fires first on the main thread (freeing cursors and setting req->cursors = NULL), and then the reply callback fires after UnblockClient is called by the background thread, replyWithCursors will call array_len(NULL) which dereferences an invalid negative-offset pointer, causing a segfault. A timedOut or NULL-cursors guard is needed before the replyWithCursors call.
Additional Locations (1)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #8657 +/- ##
==========================================
+ Coverage 81.65% 81.70% +0.05%
==========================================
Files 463 463
Lines 63375 63567 +192
Branches 20787 20785 -2
==========================================
+ Hits 51747 51938 +191
- Misses 11417 11419 +2
+ Partials 211 210 -1
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:
|
| if (!req->storedReplyState.hasStoredResults) { | ||
| // Background thread didn't store results - some early error occurred. | ||
| if (QueryError_HasError(&req->storedReplyState.err)) { | ||
| QueryErrorsGlobalStats_UpdateError(QueryError_GetCode(&req->storedReplyState.err), 1, COORD_ERR_WARN); |
There was a problem hiding this comment.
Wrong error stats category in standalone reply callback
Medium Severity
HybridQueryReplyCallback uses COORD_ERR_WARN when updating error stats, but this callback is explicitly for "non-internal hybrid requests (STANDALONE)" as stated in the comment on line 822. Standalone shard-level errors need SHARD_ERR_WARN. The sibling HybridQueryCursorReplyCallback (line 809) and HybridQueryTimeoutFailCallback (line 785) both correctly use SHARD_ERR_WARN. The analogous QueryReplyCallback in aggregate_exec.c uses !IsInternal(req) which evaluates to SHARD_ERR_WARN for non-internal requests.
There was a problem hiding this comment.
Standalone shards are considered as coordinator in the info metrics
| HybridRequest_UnlockCursors(hreq); | ||
|
|
||
| // Reply with timeout error | ||
| QueryErrorsGlobalStats_UpdateError(QUERY_ERROR_CODE_TIMED_OUT, 1, SHARD_ERR_WARN); |
There was a problem hiding this comment.
Timeout callback uses wrong error metric for standalone mode
Medium Severity
HybridQueryTimeoutFailCallback hardcodes SHARD_ERR_WARN when reporting timeout errors, but this callback is shared between internal (shard) and standalone modes. For standalone, errors need to be classified as COORD_ERR_WARN per the documented convention ("Standalone shards are considered as coordinator in the info metrics"). The existing QueryTimeoutFailCallback in aggregate_exec.c correctly uses !IsInternal(req) to differentiate, and the PR's own HybridQueryReplyCallback correctly uses COORD_ERR_WARN for standalone. This causes timeout errors in standalone FT.HYBRID to be misattributed to shard-level metrics instead of coordinator-level metrics.
Additional Locations (1)
0c81b7d to
0eccfc3
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 4 total unresolved issues (including 3 from previous reviews).
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
3688d0b to
3bda58f
Compare
|




Describe the changes in the pull request
Current: FT.HYBRID queries with
ON_TIMEOUT failpolicy do not properly handle timeouts at the shard level when running with background workers.Change: Implements shard-level
failtimeout policy for Hybrid Search by adding timeout/reply callbacks toHybridRequestsimilar to the pattern used in #8609 (coordinator level) and #8420 (shard level for Search/Aggregate). Key changes include:HybridQueryTimeoutFailCallbackandHybridQueryReplyCallbackfor standalone modeHybridQueryCursorReplyCallbackfor internal (_FT.HYBRID) cursor repliesHybridRequestfor reply callback pathOutcome: FT.HYBRID queries respect
ON_TIMEOUT failpolicy at the shard level, returning a timeout error instead of hanging when timeouts occur during multi-threaded execution.Which additional issues this PR fixes
Main objects this PR modified
src/hybrid/hybrid_exec.c- Added timeout/reply callbacks and cursor storage logicsrc/hybrid/hybrid_request.h- Addedcursorsarray field to HybridRequestsrc/info/info_redis/block_client.c/h- Generified BlockClientCtx for reusetests/pytests/test_blocked_client_timeout.py- Added FT.HYBRID timeout testsMark if applicable
Release Notes
Note
Medium Risk
Touches blocked-client timeout/reply callback wiring and cross-thread cleanup for
FT.HYBRID, which is concurrency-sensitive and could cause leaks or double-frees if wrong. Test coverage is expanded but failures would affect query execution under timeout conditions.Overview
Implements shard-level
ON_TIMEOUT failhandling forFT.HYBRIDwhen running in background workers by adding dedicated timeout/reply callbacks and synchronizing cursor creation/cleanup via a newHybridRequestcursor mutex + stored cursor list.Generalizes blocked-client setup by replacing
BlockQueryClientWithTimeout’s AREQ-specific signature with aBlockClientCtx(privdata + callbacks + AST + free hook), updating search/aggregate and hybrid callers accordingly. Adds ENABLE_ASSERT-only debug commands to pause before/after hybrid cursor storage to deterministically test timeout races, and extends pytest coverage to includeFT.HYBRIDshard timeout and new cursor-storage pause scenarios.Written by Cursor Bugbot for commit ca439a6. This will update automatically on new commits. Configure here.