Repository navigation
MOD-14076 FT.CURSOR READ: honor RETURN_STRICT timeout policy on the coordinator - #9451
Conversation
🛡️ Jit Security Scan Results✅ No security findings were detected in this PR
Security scan by Jit
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #9451 +/- ##
==========================================
+ Coverage 81.71% 81.82% +0.11%
==========================================
Files 501 502 +1
Lines 68232 68898 +666
Branches 24668 25091 +423
==========================================
+ Hits 55756 56379 +623
- Misses 12238 12281 +43
Partials 238 238
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:
|
imp DistCursorReadTimeoutReturnStrictClient
move stored->cursor set to before send chunk
remove error for spec
…_return_strict_coord
lerman25
left a comment
There was a problem hiding this comment.
Great jobs without any ASAK at all
Some comments
| disconnect after BG calls `RM_UnblockClient`, while `reply_callback` is | ||
| skipped when `bc->client == NULL`. Pause is rejected because BG-side rows | ||
| already drained from the pipeline are lost when the AREQ is freed; pausing | ||
| would let a retry silently skip those rows. Free is loud and consistent. |
There was a problem hiding this comment.
Design document accidentally committed to repository
Low Severity
A 1209-line internal design document was committed to the repository root. A reviewer explicitly commented "Remove file" on this document, indicating it was not intended for inclusion in the final PR.
Reviewed by Cursor Bugbot for commit 571486b. Configure here.
|
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.
Reviewed by Cursor Bugbot for commit 3cee641. Configure here.
| CoordRequestCtx_UnlockSetRequest(reqCtx); | ||
| cursorRead(ctx, cursor, count, false); | ||
| return REDISMODULE_OK; | ||
| } |
There was a problem hiding this comment.
Missing requiresAggregateResultsSync propagation for cursor-read AREQ path
Low Severity
coordCursorReadReturnStrict relies on the AREQ's requiresAggregateResultsSync being true (set during the original FT.AGGREGATE), which enables the startPipelineCommon bail-out. If the originating FT.AGGREGATE did not use RETURN_STRICT but the cursor's timeout policy was later changed (e.g., via global config), or if the AREQ was created through a path that doesn't set this flag, the TryClaim || TimedOut check at startPipelineCommon would be skipped and the timer's wait could hang indefinitely. The code should assert or explicitly set requiresAggregateResultsSync = true in this function since the path is exclusively for RETURN_STRICT.
Reviewed by Cursor Bugbot for commit 3cee641. Configure here.
There was a problem hiding this comment.
Why would that happen?
@meiravgri He is wrong right?
There was a problem hiding this comment.
yes. we cache the timeout policy in the cursor
lerman25
left a comment
There was a problem hiding this comment.
Your amazing grand finale
Thank you 💚






Current: On the coordinator,
FT.CURSOR READdid not honor theRETURN_STRICTtimeout policy. A cursor created by anFT.AGGREGATE … TIMEOUT … ON_TIMEOUT RETURN_STRICTcommand fell through the same path used by the defaultReturnpolicy, so the coord-side BC timeout was never armed and partial results / errors were not surfaced under the strict contract. As a side issue, the coord-path cursor reply always wrote0as the cursor id rather than echoing the livecid.Change: Wires the coordinator
FT.CURSOR READend-to-end forRETURN_STRICT:CursorCommand(module.c) —"Cursor not found"only afterRSCursorReadCommandran on the worker (postDIST_THPOOLdispatch and BC arming). With the newfoundfield onCursors_PeekTimeoutInfo,CursorCommandnow rejects unknown cids inline on the main thread (no worker dispatch, no BC arming) so theRETURN_STRICTtimer can later trustargv[3]without re-peeking.reply_callback/timeout_callbackalso forRETURN_STRICT. ForRETURN_STRICT, installs the newDistCursorReadTimeoutReturnStrictClienttimeout callback and tags theCoordRequestCtxviaCoordRequestCtx_SetCursorReadReturnStrict(true)soRSCursorReadCommandlater routes intocoordCursorReadReturnStrict.coordCursorReadReturnStrict(aggregate_exec.c) — new worker entrypoint thatRSCursorReadCommanddispatches to when the request ctx is flagged forRETURN_STRICT. Atomically performsTimedOutcheck +Cursors_TakeForExecution+AREQ_ResetForCursorReadReturnStrict+CoordRequestCtx_SetRequestunder a singlesetRequestLockcritical section, so the timer can treatreq == NULLas proof that BG has not yet taken the cursor.DistCursorReadTimeoutReturnStrictClient(dist_aggregate.c) — new BC timeout callback. LockssetRequestLock, setsTimedOut, and readsreq:req == NULL(scenario 1: BG didn’t take the cursor): replies[empty, cid]directly viacoord_cursor_read_reply_timeout_empty. Cursor stays paused and is reusable on the user’s next read.req != NULL(scenarios 2/3): wakes the abort channel, waits onaggregateResultsDone, then either drains residual shard replies and serializes the (possibly empty) partial results envelope (hasStoredResults == true) or flushes the storedQueryErrorto the client (hasStoredResults == false).rpnetNext(coord/rpnet.c) — checksAREQ_TimedOut(req)at the top of every iteration and returnsRS_RESULT_TIMEDOUTif set. Makes the timer's TimedOut flag take effect immediately.serializeAndReplyResults_Resp{2,3}(aggregate_exec.c) —cursor_doneno longer flips onRS_RESULT_TIMEDOUTunderRETURN_STRICT(previously onlyReturnwas treated this way). Keeps the cursor reusable acrossRETURN_STRICTtimeout reads.AREQ_ReplyOrStoreError(aggregate_exec.c) — adds a defensiveAREQ_SignalAggregateResultsCompletein theuseReplyCallbackbranch. Currently unreachable on the coord cursor-read path (no coord caller bails here while the timer is waiting); kept as a future-proof invariant for any error bail that happens after the timer has begun waiting. No-op for the existing FAIL callers.AREQ_ResetForCursorReadReturnStrict(aggregate_request.c) — replaces the narrowerAREQ_ResetAggregateResultsClaim. ClearsaggregatingResults,aggregateResultsDone,timedOut, andRPNet::drainOnlybetween cursor chunks.RPSorter::base.Nextis intentionally NOT reset byAREQ_ResetForCursorReadReturnStrict. TherpsortNext_Yieldlatch installed by the SORTBY TIMEDOUT path freezes the heap as a sorted snapshot drained one chunk per follow-up cursor read; resetting it would restart sorting from scratch and break snapshot-pop semantics.runCursor(aggregate_exec.c) — stashstoredReplyState.cursorbeforesendChunkso the timer that wakes from the store+signal site never observes a NULL handle and skip cursor disposal.sendChunk(aggregate_exec.c) — emitsreq->cursor_idinstead of literal0in both the results and end-of-cursor replies so cursor-shaped envelopes always preserve the live cid.Cursors_PeekTimeoutInfo(cursor.{c,h}) — adds afoundfield so callers can disambiguate "no such cursor" from "cursor exists withTIMEOUT 0".Timer-vs-BG scenarios handled by
DistCursorReadTimeoutReturnStrictClientCursors_TakeForExecutionreq == NULLTimedOutcheck incoordCursorReadReturnStrictshort-circuits without taking[empty, cid]viacoord_cursor_read_reply_timeout_emptyreq != NULL;hasStoredResultstrue (TIMEDOUT bail) or false (pre-pipeline error)(!TryClaim || TimedOut)check atstartPipelineCommonbails withRS_RESULT_TIMEDOUTand stores an empty result set, or an early-exit incursorRead(e.g. spec dropped) routes throughAREQ_ReplyOrStoreError[results, cid]afterdrainPartialResultsAfterTimeoutharvests any shard replies already buffered in the MR channel — typically non-empty (results bail), or-ERR …(error bail)req != NULL;hasStoredResults == truerpnetNextreturnsRS_RESULT_TIMEDOUTonce the flag is observed;sendChunkstores the partial prefix and signals[results, cid]combining the pipeline's stored prefix with anythingdrainPartialResultsAfterTimeoutharvests from residual channel repliesSORTBY-shaped pipelines: the
rpsortNext_Yieldlatch from PR [MOD-13617] [Agg] Coordinator: extend RETURN_STRICT partial results to SORTBY pipelines #9366 is installed during the originalFT.AGGREGATEwhen the sorter is mid-accumulation and getsRS_RESULT_TIMEDOUTfromRPNet. By the time the cursor is open, the sorter is already in pop mode (either a fully sorted heap or the latched snapshot) and no longer pulls fromRPNet, so cursor reads just drain the heap one chunk at a time.AREQ_ResetForCursorReadReturnStrictdeliberately preservesRPSorter::base.Nextbetween reads so the snapshot survives.Outcome: Coordinator
FT.CURSOR READnow honorsRETURN_STRICT:[partial-results, cid](withcidpreserved), or[empty, cid]if BG never took the cursor — the cursor remains reusable.-ERRreply with stats parity to the inline path, and the cursor is freed.Testing & debug helpers
tests/pytests/test_blocked_client_timeout.py(~565 lines) for the coordRETURN_STRICTcursor-read flow: scenarios 1/2/3, SORTBY-shaped pipelines, and free-counter assertions.#ifdef ENABLE_ASSERTsync pointSYNC_POINT_BEFORE_RPNET_NEXT(inrpnetNext) for deterministic race exercising in tests.#ifdef ENABLE_ASSERTdebug counterCoordReqCtxFreeDebug_Increment/_GetCount, bumped on everyCoordRequestCtx_Free, exposed viaFT.DEBUG QUERY_CONTROLLER GET_COORD_REQ_CTX_FREE_COUNTso tests can observefree_privdatahas fired without blocking inside the callback.Main objects this PR modified
CursorCommand/RSCursorReadCommand— coord-side dispatch forRETURN_STRICTcursor reads.DistCursorReadTimeoutReturnStrictClient(new) — BC timeout callback for the coord cursor-read path.coordCursorReadReturnStrict(new) — worker entrypoint enforcing the take + publish lock window.rpnetNext— TimedOut short-circuit on follow-up cursor reads.serializeAndReplyResults_Resp{2,3}— keep cursor open onRETURN_STRICTtimeout.AREQ_ReplyOrStoreError— defensive timer signal on theuseReplyCallbackerror branch.AREQ_ResetForCursorReadReturnStrict(replacesAREQ_ResetAggregateResultsClaim) — per-chunk sync-state reset.runCursor/sendChunk— earlier cursor stash;cidpreserved in cursor-shaped replies.Cursors_PeekTimeoutInfo— addsfoundto allow main-thread cid validation.CoordRequestCtx— newisCursorReadReturnStrictflag and getter/setter.coord_cursor_read_reply_timeout_empty(new inreply_empty.{c,h}) — scenario-1 cursor-shaped empty + cid reply.debug_commands.{c,h}) and pytest coverage intests/pytests/test_blocked_client_timeout.py.Mark if applicable
Release Notes
Coordinator
FT.CURSOR READnow correctly enforces theRETURN_STRICTtimeout policy: on deadline expiry the client receives the standard cursor-shaped envelope with any partial results and the live cursor id, and the cursor remains reusable for subsequent reads.Note
Medium Risk
Touches coordinator cursor-read timeout handling and cross-thread synchronization (blocked-client timers, cursor lifecycle, rpnet), which can affect correctness and resource cleanup under race conditions.
Overview
Coordinator
FT.CURSOR READnow honorsON_TIMEOUT RETURN_STRICTby validating cursor existence on the main thread (Cursors_PeekTimeoutInfo.found), arming a blocked client with a newDistCursorReadTimeoutReturnStrictClient, and routing worker execution through a RETURN_STRICT-aware path that checksTimedOutbefore taking the cursor.Timeout handling is updated to wait for BG completion, wake abort channels, drain partial shard replies, and reply with preserved cursor ids (including a new
coord_cursor_read_empty_reply_timeoutfast-path when the timer fires before BG takes the cursor). Cursor-read sync state is reset per chunk via newAREQ_ResetForCursorReadReturnStrict(clears timedOut + rpnetdrainOnly),rpnetNextshort-circuits onTimedOut, and cursor-shaped replies now echoreq->cursor_idinstead of0.Adds debug/test support (new sync points, coord-cursor delete debug command, free counter) and expands pytest coverage for multiple timeout race scenarios, RESP2/RESP3 reply shapes, and regression checks around delayed
free_privdatabehavior.Reviewed by Cursor Bugbot for commit 3cee641. Bugbot is set up for automated code reviews on this repo. Configure here.