Skip to content

[MOD-14327] [AGG/SEARCH/HYBRID] Use BlockClient reply_callback to reply - #8609

Merged
lerman25 merged 23 commits into
masterfrom
omerl-move-reply-to-callback
Mar 11, 2026
Merged

lerman25 merged 23 commits into
masterfrom
omerl-move-reply-to-callback

Conversation

@lerman25

@lerman25 lerman25 commented Mar 4, 2026 •

Copy link
Copy Markdown
Collaborator

Describe the changes in the pull request

Current: FT.AGGREGATE, FT.SEARCH, and FT.HYBRID coordinator commands with ON_TIMEOUT FAIL policy reply directly from background threads. If timeout fires while the background thread replies, the timeout callback busy-waits on the main thread, waiting for the background thread to finish replying. The background thread successfully writes the reply to the buffer, but the reply buffer flush to the client happens on the main thread. Since the main thread is occupied by the busy-waiting timeout callback, the buffer is never flushed and the client never receives the response.

Change: Refactor the coordinator execution path to use a reply_callback pattern. Background threads now store results in the request structure and call UnblockClient, allowing the main thread's reply callback to handle serialization.

Outcome: Consistent timeout handling across all coordinator commands with FAIL policy, eliminating double-reply races and ensuring thread-safe serialization.

Which additional issues this PR fixes

Related to #8420

Main objects this PR modified

  • aggregate_exec.c - Refactored sendChunk_Resp2/3 to use modular helpers (handleSendChunkError, prepareSendChunkReply, finishSendChunkReply, serializeAndReplyResults)
  • hybrid_exec.c - Added equivalent helpers for hybrid path (serializeAndReplyResults_hybrid, serializeStoredResults_hybrid, HREQ_StoreResults)
  • coord_request_ctx.c/h - Unified request context for coordinator timeout synchronization
  • dist_hybrid.c - Updated DistHybridReplyCallback to use stored results
  • hybrid_request.h - Added isCoord flag and ChunkReplyState for reply_callback path

Mark if applicable

  • This PR introduces API changes
  • This PR introduces serialization changes

Release Notes

  • This PR requires release notes
  • This PR does not require 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
Changes coordinator/worker execution to serialize replies on the main thread via reply_callback, affecting timeout, cursor lifecycle, and error propagation paths across FT.SEARCH/FT.AGGREGATE/FT.HYBRID. Risk is moderate due to concurrency/ownership refactors and new stored-state cleanup logic that could impact memory management or double-reply edge cases.

Overview
Switches ON_TIMEOUT FAIL execution to a reply_callback model so background workers no longer write replies directly; instead they store results/errors on the request and UnblockClient triggers main-thread serialization.

Adds ChunkReplyState (stored results, cloned QueryError, cached serialization state, and a non-owning cursor handle) and ensures cleanup via ChunkReplyState_Destroy, removing the prior atomic reply-claim/busy-wait mechanism.

Updates blocking-client plumbing (BlockQueryClientWithTimeout, ConcurrentSearchBlockClientCtx, coordinator hybrid wiring) to require both reply_callback and timeout callbacks for FAIL policy, and extends tests + debug controls to pause before/after result storage to cover timeout races (including cursor reads under FAIL).

Written by Cursor Bugbot for commit 072a16a. This will update automatically on new commits. Configure here.

@lerman25 lerman25 added enforce:coverage Run coverage flow even on draft pull request enforce:sanitize Run sanitizer flow even on draft pull request labels Mar 4, 2026
@lerman25
lerman25 requested a review from Copilot March 4, 2026 22:49
@jit-ci

jit-ci Bot commented Mar 4, 2026 •

Copy link
Copy Markdown

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ No security findings were detected in this PR


Security scan by Jit

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors FAIL-timeout handling to use RedisModule reply_callback (reply-on-unblock) instead of replying directly from background threads, aiming to prevent double-reply races and simplify timeout behavior across coordinator (FT.HYBRID) and worker-executed queries.

Changes:

  • Split blocked-client callbacks into reply_callback and timeout_callback, and wire them through concurrent execution and BlockQueryClientWithTimeout.
  • Add “store results then reply in callback” paths for AREQ and HybridRequest under FAIL policy (including new stored reply state).
  • Update timeout/reply handling logic in distributed hybrid coordinator flow and adjust a related pytest.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
tests/pytests/test_blocked_client_timeout.py Adjusts FT.HYBRID test parameters/comments for FAIL-policy no-timeout flow.
src/module.c Switches coordinator blocked-client handling to reply/timeout callbacks for DistHybrid FAIL policy.
src/info/info_redis/block_client.h Extends BlockQueryClientWithTimeout to accept a reply callback in addition to timeout callback.
src/info/info_redis/block_client.c Passes reply/timeout callbacks into RedisModule_BlockClient.
src/hybrid/hybrid_request.h Adds coordinator flag + stored reply state to HybridRequest.
src/hybrid/hybrid_request.c Removes old reply-state helpers; retains timeout helpers and HybridRequest init/free logic.
src/hybrid/hybrid_exec.h Declares helpers to store results and serialize stored results for reply-callback flow.
src/hybrid/hybrid_exec.c Implements storing results for reply_callback, refactors serialization helpers, and adds reply-callback serialization path.
src/coord/hybrid/dist_hybrid.h Declares new coordinator reply callback for DistHybrid.
src/coord/hybrid/dist_hybrid.c Implements DistHybrid reply callback and simplifies timeout callback; updates cleanup flow.
src/coord/coord_request_ctx.h Updates coordinator request context API/docs for reply_callback model; adds GetRequest.
src/coord/coord_request_ctx.c Implements GetRequest and removes reply-state claiming APIs.
src/concurrent_ctx.h Renames blocked-client context fields to reply_callback / timeout_callback.
src/concurrent_ctx.c Uses the new callback fields when blocking clients.
src/aggregate/aggregate_request.c Adds teardown for stored reply state (results + stored error).
src/aggregate/aggregate_exec.c Refactors chunk serialization, adds reply_callback for FAIL policy, stores results/error for main-thread reply.
src/aggregate/aggregate.h Introduces ChunkReplyState stored reply state and embeds it in AREQ; updates sync-context docs.
Comments suppressed due to low confidence (1)

src/aggregate/aggregate_exec.c:1122

  • blockedClientReqCtx_destroy() no longer decrements the transferred AREQ reference, but AREQ_Execute_Callback only releases that ref via AREQ_Execute() on the success path. On early error returns (e.g., index dropped / prepareExecutionPlan failure), the request is never decref’d, so it will leak (BlockedQueryNode only releases its own incremented ref). Ensure the background worker always releases its owned AREQ reference on all non-cursor paths, including error paths.
static void blockedClientReqCtx_destroy(blockedClientReqCtx *BCRctx) {
  RedisModule_BlockedClientMeasureTimeEnd(BCRctx->blockedClient);
  void *privdata = RedisModule_BlockClientGetPrivateData(BCRctx->blockedClient);
  RedisModule_UnblockClient(BCRctx->blockedClient, privdata);

  // Note: We don't call AREQ_DecrRef here despite owning the transferred reference.
  // The reference is released by AREQ_Execute (shared code path also used by the main thread).

  WeakRef_Release(BCRctx->spec_ref);
  rm_free(BCRctx);
}

// Helper for error handling in AREQ_Execute_Callback.
// For FAIL policy (useReplyCallback=true): stores error for QueryReplyCallback to handle.
// For RETURN policy: replies with error directly.
static void ReplyOrStoreError(bool useReplyCallback, AREQ *req, RedisModuleCtx *ctx, QueryError *status) {
  if (useReplyCallback) {
    // Deep copy since QueryError contains heap-allocated strings.
    // QueryReplyCallback will clear the stored error after replying.
    QueryError_CloneFrom(status, &req->storedReplyState.err);
  } else {
    QueryError_ReplyAndClear(ctx, status);
  }
}

void AREQ_Execute_Callback(blockedClientReqCtx *BCRctx) {
  AREQ *req = blockedClientReqCtx_getRequest(BCRctx);

  // Check if timed out while in the job queue.
  if (AREQ_TimedOut(req)) {
    // Timeout callback already replied.
    AREQ_DecrRef(req);
    blockedClientReqCtx_destroy(BCRctx);
    return;
  }

  if (IsProfile(req)) {
    req->profileClocks.profileQueueTime = rs_wall_clock_elapsed_ns(&req->profileClocks.initClock);
  }

  RedisModuleCtx *outctx = RedisModule_GetThreadSafeContext(BCRctx->blockedClient);
  QueryError status = QueryError_Default();

  // For FAIL policy, we must NOT reply directly from the background thread.
  // The reply_callback (QueryReplyCallback) handles all replies to avoid double-reply issues
  bool useReplyCallback = (req->reqConfig.timeoutPolicy == TimeoutPolicy_Fail);

  StrongRef execution_ref = IndexSpecRef_Promote(BCRctx->spec_ref);
  if (!StrongRef_Get(execution_ref)) {
    // The index was dropped while the query was in the job queue.
    QueryError_SetCode(&status, QUERY_ERROR_CODE_DROPPED_BACKGROUND);
    ReplyOrStoreError(useReplyCallback, req, outctx, &status);
    RedisModule_FreeThreadSafeContext(outctx);
    blockedClientReqCtx_destroy(BCRctx);
    return;
  }

  // Cursors are created with a thread-safe context, so we don't want to replace it
  RedisSearchCtx *sctx = AREQ_SearchCtx(req);
  if (!(AREQ_RequestFlags(req) & QEXEC_F_IS_CURSOR)) {
    sctx->redisCtx = outctx;
  }

  // lock spec
  RedisSearchCtx_LockSpecRead(sctx);
  if (prepareExecutionPlan(req, &status) != REDISMODULE_OK) {
    RedisSearchCtx_UnlockSpec(sctx);
    goto error;
  }

  if (AREQ_RequestFlags(req) & QEXEC_F_IS_CURSOR) {
    RedisModule_Reply _reply = RedisModule_NewReply(outctx), *reply = &_reply;
    int rc = AREQ_StartCursor(req, reply, execution_ref, &status, false);
    RedisModule_EndReply(reply);
    if (rc != REDISMODULE_OK) {
      goto error;
    }
  } else {
    AREQ_Execute(req, outctx);
  }

  // If the execution was successful, we either:
  // 1. Freed the request (if it was a regular query)
  // 2. Kept it as the cursor's state (if it was a cursor query)
  // Either way, we don't want to free `req` here. we set it to NULL so that it won't be freed with the context.
  blockedClientReqCtx_setRequest(BCRctx, NULL);
  goto cleanup;

error:
  ReplyOrStoreError(useReplyCallback, req, outctx, &status);

cleanup:
  // No need to unlock spec as it was unlocked by `AREQ_Execute` or will be unlocked by `blockedClientReqCtx_destroy`
  RedisModule_FreeThreadSafeContext(outctx);
  IndexSpecRef_Release(execution_ref);
  blockedClientReqCtx_destroy(BCRctx);
}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/aggregate/aggregate_exec.c Resolved
Comment thread src/aggregate/aggregate.h Resolved
Comment thread src/hybrid/hybrid_exec.c Resolved
Comment thread src/hybrid/hybrid_exec.c Resolved
Comment thread src/hybrid/hybrid_exec.c Resolved
Comment thread src/hybrid/hybrid_request.h Resolved
Comment thread src/coord/hybrid/dist_hybrid.c Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/coord/hybrid/dist_hybrid.c Resolved
Comment thread src/hybrid/hybrid_exec.c Resolved
Comment thread src/aggregate/aggregate_exec.c Resolved
Comment thread src/aggregate/aggregate_exec.c Resolved
Comment thread src/aggregate/aggregate_exec.c Resolved
Comment thread src/aggregate/aggregate.h Resolved
@lerman25
lerman25 requested a review from Copilot March 4, 2026 23:34
@lerman25
lerman25 force-pushed the omerl-move-reply-to-callback branch from ca0d48a to f222a2e Compare March 4, 2026 23:36
@lerman25
lerman25 requested review from Copilot and removed request for Copilot March 4, 2026 23:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/hybrid/hybrid_exec.c Resolved
Comment thread src/aggregate/aggregate_exec.c Resolved
Comment thread src/coord/coord_request_ctx.h Resolved
@lerman25
lerman25 force-pushed the omerl-move-reply-to-callback branch from fe4093f to 06f8b70 Compare March 5, 2026 09:03
@lerman25
lerman25 marked this pull request as ready for review March 5, 2026 09:08
@lerman25 lerman25 changed the title Omerl move reply to callback [MOD-14327] [AGG/SEARCH/HYBRID] Use BlockClient reply_callback to reply Mar 5, 2026
Comment thread src/aggregate/aggregate_exec.c Resolved
Comment thread src/coord/hybrid/dist_hybrid.c Resolved
Comment thread src/aggregate/aggregate_exec.c Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 8 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/aggregate/aggregate_exec.c Resolved
Comment thread src/aggregate/aggregate_exec.c Resolved
Comment thread src/aggregate/aggregate_request.c Resolved
Comment thread src/hybrid/hybrid_exec.c Resolved
Comment thread src/hybrid/hybrid_request.c Resolved
Comment thread src/coord/coord_request_ctx.c Resolved
Comment thread src/coord/hybrid/dist_hybrid.c Resolved
Comment thread src/aggregate/aggregate_exec.c Resolved
QueryError_ClearError(status);
} else {
return ctx->areq ? AREQ_GetReplyState(ctx->areq) : ReplyState_NotReplied;
QueryError_ReplyAndClear(ctx, status);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing ClearError before CloneFrom causes silent clone failure

Medium Severity

CoordRequestCtx_ReplyOrStoreError calls QueryError_CloneFrom(status, &req->preRequestError) without first calling QueryError_ClearError(&req->preRequestError). The Rust implementation of QueryError_CloneFrom silently returns without cloning if the destination already holds an error (i.e., is not in OK state). Both AREQ_ReplyOrStoreError and HREQ_ReplyOrStoreError correctly call QueryError_ClearError on the destination before cloning, but this function omits it, breaking the established pattern.

Additional Locations (2)

Fix in Cursor Fix in Web

CoordRequestCtx_ReplyOrStoreError(reqCtx, ctx, status);
} else {
HREQ_ReplyOrStoreError(hreq, ctx, status);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error statistics double-counted in coordinator hybrid FAIL path

Medium Severity

When useReplyCallback is true (FAIL policy), DistHybridCleanups calls QueryErrorsGlobalStats_UpdateError at line 779 before storing the error. Then DistHybridReplyCallback calls QueryErrorsGlobalStats_UpdateError again (lines 917 and 930) when it processes the stored error. This causes every coordinator hybrid error to be counted twice in global statistics. The standalone AREQ path (AREQ_Execute_Callback) avoids this by not tracking stats before calling AREQ_ReplyOrStoreError.

Additional Locations (1)

Fix in Cursor Fix in Web

Comment thread src/aggregate/aggregate.h Outdated
* - In normal flow, QueryReplyCallback calls Cursor_Free/Cursor_Pause and clears this field.
*
* **Timeout edge case**:
* - If timeout fires before QueryReplyCallback runs, AREQ_Free must clean up the cursor.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Can't we leave it for the worker always?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

related to #8609 (comment)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed comment, and replied to that thread

QueryError_ClearError(status);
} else {
return ctx->areq ? AREQ_GetReplyState(ctx->areq) : ReplyState_NotReplied;
QueryError_ReplyAndClear(ctx, status);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing pre-clear before clone risks memory leak

Medium Severity

CoordRequestCtx_ReplyOrStoreError calls QueryError_CloneFrom into preRequestError without first calling QueryError_ClearError on the destination. Both peer functions AREQ_ReplyOrStoreError and HREQ_ReplyOrStoreError clear the destination before cloning to avoid leaking any existing heap-allocated error strings. If preRequestError ever holds data when this function is called, the old strings would be overwritten without being freed.

Additional Locations (2)

Fix in Cursor Fix in Web

Comment thread src/aggregate/aggregate.h Outdated
typedef struct {
SearchResult **results; // Aggregated results array (NULL if not aggregated yet)
int rc; // Pipeline return code (RS_RESULT_OK, RS_RESULT_EOF, etc.)
bool cursor_done; // Whether cursor is exhausted (for cursor queries)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused cursor_done field in ChunkReplyState struct

Low Severity

The cursor_done field in ChunkReplyState is declared and documented as "Whether cursor is exhausted (for cursor queries)" but is never set or read anywhere. The actual cursor-done computation happens in ChunkSerializeState (a separate struct), not in ChunkReplyState. This dead field adds confusion since readers might expect it to be part of the stored state used by the reply_callback.

Fix in Cursor Fix in Web

"""Test timeout occurring after storing results for FT.AGGREGATE in standalone."""
self._test_fail_timeout_after_store_impl(['FT.AGGREGATE', 'idx', '*'])

def test_no_timeout_cursor(self):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same test name? Under a different class?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same name under different class (SA & Cluster)


if (req) {
// Cursor reads don't use reply_callback, so clear the flag.
req->useReplyCallback = false;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not? By design, or will it be added in a follow-up?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stored->cursor = NULL;
}

// No AREQ_DecrRef here - BlockedQueryNode holds the reference, released via FreeQueryNode.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But in the case of a cursor, we may have already freed it. Is this intended?

@lerman25 lerman25 Mar 10, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without Cursor:
AREQ ownership: shared between blockedClientReqCtx (background thread) and BlockedQueryNode (timeout callback, reply callback).
Take a reference for the timeout callback access via node->privdata.
The BlockedQueryNode reference is released in FreeQueryNode via the freePrivData callback after timeout/reply callback completes.
The blockedClientReqCtx reference is released in blockedClientReqCtx_destroy,
With Cursor:
The cursor takes ownership of AREQ from the blockedClientReqCtx

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

CoordRequestCtx_ReplyOrStoreError(reqCtx, ctx, status);
} else {
HREQ_ReplyOrStoreError(hreq, ctx, status);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing QueryError_HasError guard in DistHybridCleanups

Low Severity

DistHybridCleanups removed the old guard that skipped error reply when !QueryError_HasError(status). The new code reaches QueryErrorsGlobalStats_UpdateError and CoordRequestCtx_ReplyOrStoreError/HREQ_ReplyOrStoreError even when status has no error. While all current callers either set an error or are caught by the timeout check, the removed defensive guard makes this function fragile against future callers that might invoke it without setting an error when not timed out, leading to tracking a bogus error code and storing/replying with an empty error.

Fix in Cursor Fix in Web

Comment thread src/hybrid/hybrid_exec.c
hreq->storedReplyState.rc = rc;
hreq->storedReplyState.cv = cv;
hreq->storedReplyState.hasStoredResults = true;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stored error not cloned in HREQ_StoreResults unlike AREQ path

Medium Severity

HREQ_StoreResults doesn't clone the qctx->err error state into storedReplyState.err, unlike AREQ_StoreResults which explicitly clones it. In serializeStoredResults_hybrid, the error is recovered via HybridRequest_GetError, but qctx->err still points to a now-invalid stack variable from the background thread's RSExecDistHybrid frame. The workaround at line 464 (qctx->err = &err) only patches over this, but any code that accessed qctx->err between sendChunk_hybrid returning and serializeStoredResults_hybrid running would hit a dangling pointer.

Additional Locations (1)

Fix in Cursor Fix in Web

GuyAv46
GuyAv46 previously approved these changes Mar 10, 2026
@lerman25
lerman25 added this pull request to the merge queue Mar 10, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 11, 2026
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
15.8% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@lerman25
lerman25 marked this pull request as draft March 11, 2026 09:16
auto-merge was automatically disabled March 11, 2026 09:16

Pull request was converted to draft

@lerman25
lerman25 marked this pull request as ready for review March 11, 2026 09:16
@lerman25
lerman25 enabled auto-merge March 11, 2026 09:24

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

CoordRequestCtx_ReplyOrStoreError(reqCtx, ctx, status);
} else {
HREQ_ReplyOrStoreError(hreq, ctx, status);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing error guard in DistHybridCleanups before stats update

Low Severity

DistHybridCleanups unconditionally calls QueryErrorsGlobalStats_UpdateError(QueryError_GetCode(status), ...) without first checking QueryError_HasError(status). The old code had a !QueryError_HasError(status) guard that skipped the reply/stats path when no error was present. While current call sites always have an error set when not timed out, removing this guard means a future call without an error would increment a stats counter for a default/zero error code and attempt to store/reply with a non-error through CoordRequestCtx_ReplyOrStoreError or HREQ_ReplyOrStoreError.

Fix in Cursor Fix in Web

Comment thread src/hybrid/hybrid_exec.c
hreq->storedReplyState.rc = rc;
hreq->storedReplyState.cv = cv;
hreq->storedReplyState.hasStoredResults = true;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HREQ_StoreResults doesn't deep copy pipeline error state

Medium Severity

HREQ_StoreResults does not deep-copy the pipeline error state into storedReplyState.err, unlike AREQ_StoreResults which clones qctx->err. Instead, serializeStoredResults_hybrid retrieves errors via HybridRequest_GetError and points qctx->err at a local QueryError. If qctx->err originally pointed to a stack variable in the background thread's call frame (e.g., in RSExecDistHybrid), any code that accesses qctx->err before it is re-pointed in serializeStoredResults_hybrid would read a dangling pointer. The asymmetry with AREQ_StoreResults makes this fragile.

Additional Locations (1)
Fix in Cursor Fix in Web

@lerman25
lerman25 added this pull request to the merge queue Mar 11, 2026
Merged via the queue into master with commit 51c2018 Mar 11, 2026
93 of 106 checks passed
@lerman25
lerman25 deleted the omerl-move-reply-to-callback branch March 11, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants