Skip to content

v4: queued transaction tasks - no bridge for the retry proxy; tests wait rather than peek (#3402's example) - #3405

Merged
mgravell merged 1 commit into
v4from
marc/v4-retry-transaction-settle
Dec 3, 2026
Merged

mgravell merged 1 commit into
v4from
marc/v4-retry-transaction-settle

Conversation

@mgravell

@mgravell mgravell commented Dec 3, 2026

Copy link
Copy Markdown
Member

Fixes the example in #3402: QueuedResultTests.RetryTransactionFireAndForgetSharesOneCompletedTask, which flaked on Ubuntu CI and failed on every local run on net481. The wider sweep in #3402 stays open.

Cause

In v4, a queued command's Task is completed off the reader thread, through the thread pool, so a caller's continuation never runs on the reader. For a transaction, EXEC's reply settles every queued operation on the reader, and each one queues the completion of its Task. Then EXEC completes, and the caller's await tran.ExecuteAsync() resumes, also through the pool. Nothing orders the two, so a queued Task can still be incomplete for a moment after ExecuteAsync returns.

v3 differs: it set every queued Task complete before EXEC's result, and only the continuations went to the pool. Awaiting can't tell the difference. Checking IsCompleted straight after ExecuteAsync can, and that's what the test did. Restoring v3's ordering would mean deferring task completion into ExecuteAsync. That isn't worth it for a gap only visible to code that peeks, so the tests change instead, and the docs say how to fetch results.

Change

  • RespRetryTransactionExecutor notes its proxy task (NoteDispatchedTask), as the batch executor does. TaskBridge then hands that task back as it is. Before, it wrapped the task in a second completion source, completed from a continuation the proxy queues to the pool: one extra allocation per queued command, and an extra hop.
  • QueuedResultTests:
    • RetryTransactionFireAndForgetSharesOneCompletedTask now waits for the queued task, with a timeout, instead of asserting IsCompleted. It uses WhenAny because the GET faults with WRONGTYPE: the test's own HSET made the key a hash.
    • New QueuedTaskCompletesPromptlyAfterExecute covers plain and retry transactions, with and without an async state.
  • docs/Transactions.md: fetch queued results by awaiting or Wait-ing, not by peeking at IsCompleted, with a note that this differs from earlier versions.

Tests

QueuedResultTests, RetryEndToEndTests and TransactionTests, three runs each on net10.0 and net481: 528 tests per run, none failed.

…ait for queued tasks rather than peek

A queued command's task in v4 is completed off the reader, through the thread pool, so it can
trail ExecuteAsync by a moment - unlike v3, which set every queued task complete before EXEC's
result. Awaiting is unaffected; IsCompleted straight after ExecuteAsync is not. That is the
race behind #3402's example, which net481 reproduced on every run.

- RespRetryTransactionExecutor notes its proxy task (NoteDispatchedTask), so TaskBridge returns it
  as-is rather than wrapping it in a second completion source completed from a pool continuation.
- QueuedResultTests: RetryTransactionFireAndForgetSharesOneCompletedTask waits, bounded, instead
  of asserting IsCompleted; QueuedTaskCompletesPromptlyAfterExecute covers plain and retry
  transactions, with and without an async state.
- docs/Transactions.md: fetch queued results by awaiting, not by peeking; note the change from v3.
@mgravell
mgravell merged commit 9746813 into v4 Dec 3, 2026
4 of 5 checks passed
@mgravell
mgravell deleted the marc/v4-retry-transaction-settle branch December 3, 2026 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant