Repository navigation
[MOD-18502] Move coordinator AGGREGATE FAIL reply serialization off the main thread - #11552
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f9ed77dd38
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ((AREQ *)req)->useReplyCallback = ctx->useReplyCallback; | ||
| AREQ *areq = (AREQ *)req; | ||
| areq->useReplyCallback = ctx->useReplyCallback; | ||
| areq->encodeReplyInBackground = ctx->timeoutPolicy == TimeoutPolicy_Fail; |
There was a problem hiding this comment.
Count each coordinator cursor timeout only once
When a coordinator FT.CURSOR READ using ON_TIMEOUT FAIL reaches its blocked-client deadline after the worker has taken the cursor, DistAggregateTimeoutFailCallback increments timeout_error and marks the AREQ timed out, then this new direct-encoding path lets handleSendChunkError observe the same timeout and increment the metric again. The updated tests explicitly changed these cases to expect error_count=2, so one timed-out command now overreports the coordinator error metric; suppress worker-side accounting once the timeout callback has replied, or retain single-owner accounting.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 3a5e349. handleSendChunkError skips worker-side accounting when encodeReplyInBackground && AREQ_TimedOut(req). Restored +1 expectations for coordinator, shard, and standalone timeouts. The debug build and timeout suites pass (67 standalone, 100 cluster).
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3a5e3497bc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (req->encodeReplyInBackground && !AREQ_TimedOut(req) && | ||
| !(req->stateflags & QEXEC_S_ITERDONE)) { | ||
| Cursor_Pause(cursor); |
There was a problem hiding this comment.
Free standalone cursors when the blocked client disconnects
When a standalone/shard ON_TIMEOUT FAIL request with WITHCURSOR disconnects before receiving the worker-buffered reply, FreeQueryNode/FreeCursorNode discards the RedisModuleCtx, so the request is never marked timed out or disconnected. This condition therefore pauses a successful nonterminal cursor even though its reply was discarded, leaking an initial cursor until idle GC and allowing a known cursor ID to resume after silently consuming an undelivered chunk. The coordinator avoids this by checking RedisModule_BlockedClientDisconnected in DistCoordReqFreePrivData; the standalone cleanup needs equivalent disconnect propagation before finalization.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
We accept retaining standalone/shard cursors until MAXIDLE after a disconnect to keep this PR small. An interrupted cursor READ may also have consumed an undelivered chunk. We will keep the existing coordinator cleanup without adding shared disconnect plumbing in this PR.
| r->useReplyCallback = !r->encodeReplyInBackground; | ||
| blockClientCtx.replyCallback = r->useReplyCallback ? QueryReplyCallback : NULL; |
There was a problem hiding this comment.
Suppress early-error accounting after a FAIL timeout
With this callback-free FAIL selection, a deadline can fire after the worker's initial timeout check but before an early failure such as index promotion or execution-plan preparation; the timeout callback counts TIMED_OUT, then AREQ_ReplyOrStoreError or CoordRequestCtx_ReplyOrStoreError directly counts the discarded worker error as well. The fresh evidence beyond the previously reported serialization case is that the new guard exists only in handleSendChunkError, while these early-error paths now bypass it because useReplyCallback is false. Gate their direct reply/accounting on the request timeout state as well.
Useful? React with 👍 / 👎.
3a5e349 to
a2c0393
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 452717284f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
| #endif | ||
| // The timeout callback already counted errors for discarded background replies. | ||
| const bool countError = !(req->encodeReplyInBackground && AREQ_TimedOut(req)); |
There was a problem hiding this comment.
Make timeout error accounting a single atomic claim
The new guard still has a TOCTOU window: for any background ON_TIMEOUT FAIL reply, the worker can read AREQ_TimedOut(req) == false here, then the blocked-client timeout callback can set the flag and increment timeout_error, after which the worker also increments it at lines 562 or 568. Thus the single-count guarantee remains timing-dependent; the fresh evidence beyond the prior comment is that the fix only added an atomic load rather than an atomic ownership claim or synchronization covering the load and increment. Use a single atomic claim shared by the timeout callback and worker-side accounting.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
We accept this limitation. The timeout-state guard provides best-effort suppression, not exactly-once accounting: a worker that passes the check before the timeout callback runs can still count an error for a discarded reply, including a second timeout count. We are okay with those metric increments and will not add atomic accounting ownership or additional synchronization in this PR. This is an accounting limitation, not a duplicate client reply or server-crash issue. The PR description now documents this and the other accepted limitations.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fe47aac34d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| while (!profileShouldStopCollectingReplies(req)) { | ||
| MRReply_Free(rpnet->current.root); | ||
| } while (getNextReply(rpnet) != RS_RESULT_EOF); | ||
| if (getNextReply(rpnet) == RS_RESULT_EOF) { |
There was a problem hiding this comment.
Wake profile reply waits when the FAIL deadline fires
When a coordinator FT.PROFILE AGGREGATE reaches this getNextReply call while a shard's final profile reply is still pending, a concurrent FAIL timeout only sets AREQ_TimedOut; it does not call RequestSyncCtx_WakeAbortChannel. Since MRIterator_NextWithTimeout was given no deadline and its condition variable is not signaled by changing the atomic flag, the new loop cannot re-evaluate profileShouldStopCollectingReplies until that shard eventually responds. A stalled shard can therefore retain the request and a coordinator worker long past the configured deadline, and enough such requests can exhaust the coordinator pool; wake the registered abort channel from the FAIL timeout callback.
AGENTS.md reference: AGENTS.md:L268-L269
Useful? React with 👍 / 👎.
| if (policy == TimeoutPolicy_Fail || policy == TimeoutPolicy_ReturnStrict) { | ||
| handlerCtx.bcCtx.reply_callback = DistAggregateReplyCallback; | ||
| bool useReplyCallback = policy == TimeoutPolicy_ReturnStrict; | ||
| handlerCtx.bcCtx.reply_callback = useReplyCallback ? DistAggregateReplyCallback : NULL; |
There was a problem hiding this comment.
Skip warning accounting for discarded FAIL profiles
For coordinator FT.PROFILE AGGREGATE under FAIL, selecting direct worker serialization here lets a reply discarded by the timeout callback continue through trackWarnings_Resp2 or _replyWarnings, which increments timeout_warning even though the client received a timeout error instead of that warning. The changed test explicitly permits this scheduling-dependent extra metric, so repeated timed-out profiles make INFO warning telemetry inaccurate; suppress warning accounting once a background reply observes AREQ_TimedOut, just as the error paths now do.
Useful? React with 👍 / 👎.
| if (req->encodeReplyInBackground) { | ||
| // Pause after a row is encoded; signaling disarms the hook for later rows. | ||
| SyncPoint_Wait(SYNC_POINT_DURING_BACKGROUND_REPLY_ENCODE); | ||
| SyncPoint_Wait(IsCoordinator(req) ? SYNC_POINT_DURING_COORD_BACKGROUND_REPLY_ENCODE |
There was a problem hiding this comment.
Stop encoding rows after coordinator FAIL cancellation
When a coordinator FAIL deadline or client cancellation occurs after result collection has entered serialization, the new direct path continues calling serializeResult for every remaining row without checking AREQ_TimedOut; the flag is only consulted for accounting and eventual cursor cleanup. A query with a very large reply can therefore keep a coordinator worker busy and grow a reply buffer that Redis will discard, long after the caller received its timeout, allowing repeated abandoned queries to exhaust worker capacity or memory. Check cancellation between encoded rows and destroy the remaining buffered results instead of finishing the discarded reply.
AGENTS.md reference: AGENTS.md:L268-L269
Useful? React with 👍 / 👎.
|
|
🤖 Auto-backport summary
(PR #11552, Workflow run · Retry unfinished targets with |
|
Manual follow-up to the auto-backport summary:
|
…he main thread Port the FAIL path from OSS 8.10 pull request #11552 to master.
…he main thread Stop collecting shard profiles as soon as a worker reply is cancelled. Port coordinator AGGREGATE reply parity checks for results, profiles, and cursor chunks. Port the FAIL path from OSS 8.10 pull request #11552.
…he main thread Stop collecting shard profiles when a worker reply is cancelled. Exercise coordinator AGGREGATE parity for results, profiles, and cursor chunks. Port the FAIL path from OSS 8.10 pull request #11552.
…he main thread Stop collecting shard profiles when a worker reply is cancelled. Exercise coordinator AGGREGATE parity for results, profiles, and cursor chunks. Port the FAIL path from OSS 8.10 pull request #11552.


Describe the changes in the pull request
Coordinator AGGREGATE with
ON_TIMEOUT FAILserializes replies on the main thread. Move serialization to workers through the existing direct reply path used by RETURN, preserving full-chunk collection so late errors still replace the entire reply.Keep the blocked-client deadline active during encoding. Finalize coordinator cursors during free-data cleanup: pause successful nonterminal cursors and free timed-out, disconnected, or exhausted cursors. This includes PROFILE, initial WITHCURSOR requests, and cursor READ. Background error paths skip accounting when they observe that the request has timed out, across coordinator, shard, and standalone paths. This is best-effort suppression; it does not guarantee exactly-once accounting.
Follows #11534 and #11541. Rebase to master is deferred until #11543 merges.
Validation:
test_blocked_client_timeout: 67 passed / 9 skipped standalone; 100 passed / 13 skipped in a three-shard cluster. No failures.Known limitations accepted in this PR
timeout_errortwice. Metrics for a background reply may remain counted even when Redis discards that reply. We accept this without adding atomic accounting ownership or additional synchronization. This accounting limitation does not imply a duplicate client reply or a server crash.Which additional issues this PR fixes
MOD-18502
Main objects this PR modified
Mark if applicable
Release Notes