Skip to content

Fix dead code: !completedTask.IsCompleted always false in hedge timer loop#5625

Closed
Copilot wants to merge 9 commits into
masterfrom
copilot/sub-pr-5613
Closed

Fix dead code: !completedTask.IsCompleted always false in hedge timer loop#5625
Copilot wants to merge 9 commits into
masterfrom
copilot/sub-pr-5613

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 19, 2026

Task.WhenAny always returns a task already in a terminal state, so completedTask.IsCompleted is invariably true — making !completedTask.IsCompleted dead code that never triggered. The intended behavior (skip spawning new hedge requests when the timer ended abnormally) was silently broken.

Change

  • Replaced !completedTask.IsCompleted with completedTask.IsFaulted || completedTask.IsCanceled to correctly detect abnormal timer completion (cancelled via linked CTS on e2e timeout, or faulted)
  • IsCompletedSuccessfully was not used — unavailable on netstandard2.0
// Before — !IsCompleted is always false; condition reduced to just IsCancellationRequested
while (
    completedTask == hedgeTimer &&
    (!completedTask.IsCompleted || applicationProvidedCancellationToken.IsCancellationRequested));

// After — correctly detects cancelled/faulted timer
while (
    completedTask == hedgeTimer &&
    (completedTask.IsFaulted || completedTask.IsCanceled || applicationProvidedCancellationToken.IsCancellationRequested));

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

FabianMeiswinkel and others added 8 commits February 11, 2026 11:24
…gy NullRef fix

Adds 8 regression tests covering:
- Hedge CTS token cancels in-flight requests (not app CT)
- Sender receives hedge CTS token, not application token
- App cancellation prevents spawning new hedge requests (do/while fix)
- Request not accessed after disposal on cancellation
- Stream-based request path (ReadItemStreamAsync)
- Primary request fast return skips hedging
- All-transient error handling
- Concurrent hedging stress test (50 parallel requests)
…edge timer loop

Co-authored-by: kundadebdatta <87335885+kundadebdatta@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix race condition in CrossRegionHedgingAvailabilityStrategy Fix dead code: !completedTask.IsCompleted always false in hedge timer loop Feb 19, 2026
Copilot AI requested a review from kundadebdatta February 19, 2026 22:24
Base automatically changed from users/fabianm/NullRefInvestigation to master February 20, 2026 21:44
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.

6 participants