Skip to content

fix: throw from PushAsync when a queued operation times out - #581

Merged
adrianhall merged 2 commits into
CommunityToolkit:mainfrom
adrianhall:issues/578
Nov 5, 2026
Merged

adrianhall merged 2 commits into
CommunityToolkit:mainfrom
adrianhall:issues/578

Conversation

@adrianhall

Copy link
Copy Markdown
Collaborator

Closes #578

Problem

When a queued operation's HTTP request hits HttpClient.Timeout during PushAsync, the resulting TaskCanceledException is thrown from the ActionBlock<T> delegate inside QueueHandler<T>. TPL Dataflow treats an OperationCanceledException from a block delegate as cooperative cancellation, so the item is silently dropped and Completion finishes normally. AddOperationResult is never called, so PushResult.IsSuccessful stays true, nothing is reported as failed, and the operation remains queued. A subsequent PullAsync then throws because of pending operations.

Changes

  • QueueHandler<T>: catch OperationCanceledException from the job delegate, remember the first one, and rethrow it from WhenComplete() so cancellation is no longer swallowed. This also benefits the pull pipeline.
  • OperationsQueueManager.PushAsync: when an operation is canceled but the caller's CancellationToken was not canceled (i.e. a request timeout), throw a TimeoutException (inner = the original cancellation). A caller-requested cancellation still surfaces as OperationCanceledException.
  • Operations that completed before the failure are still persisted (removed from the queue) before the exception is rethrown, so they are not re-sent on retry; the timed-out operation remains queued.
  • Docs: note on push failure behavior in docs/in-depth/client/index.md.

This follows the issue's suggested option of throwing like other network failures (e.g. HttpRequestException) rather than adding a synthetic entry to FailedRequests, since FailedRequests is a ServiceResponse map and a timeout has no response.

Tests

  • QueueHandler_JobCanceled_WhenCompleteThrows
  • PushAsync_Addition_Timeout_Throws_AndKeepsOperationQueued
  • PushAsync_CallerCancellation_Throws_OperationCanceledException

All three fail without the fix and pass with it. Client test suite passes locally (Service.Integration_Tests.Delete_NotSoftDeleted_Returns204 is flaky in the full run on both main and this branch, and passes in isolation).

Notes

The related scenario in the issue (server applied the write before the client timed out, retry gets a 412) is not addressed here; it is inherent to at-least-once delivery and is better handled by conflict resolution.

TPL Dataflow treats an OperationCanceledException from an ActionBlock
delegate as cooperative cancellation, silently dropping the item. A
HttpClient.Timeout (TaskCanceledException) during push therefore left the
operation queued while PushResult.IsSuccessful stayed true.

QueueHandler now surfaces canceled jobs from WhenComplete(), and push
converts a non-caller cancellation into a TimeoutException. Completed
operations are still persisted before the exception is rethrown. A
caller-requested cancellation still surfaces as OperationCanceledException.

Closes CommunityToolkit#578
docs.automapper.org no longer resolves; the docs moved to docs.automapper.io.
This was failing the lychee link check on the docs workflow.
@adrianhall
adrianhall merged commit 15a2f88 into CommunityToolkit:main Nov 5, 2026
7 checks passed
@adrianhall
adrianhall deleted the issues/578 branch November 5, 2026 17:09
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.

PushAsync reports success when an operation times out, leaving it queued

1 participant