Stabilize CachedResponseBodyTests.Copy_SingleSegment - #68110
Open
irfanajaffer wants to merge 2 commits into
Open
Stabilize CachedResponseBodyTests.Copy_SingleSegment#68110irfanajaffer wants to merge 2 commits into
CachedResponseBodyTests.Copy_SingleSegment#68110irfanajaffer wants to merge 2 commits into
Conversation
Contributor
|
Thanks for your PR, @irfanajaffer. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
irfanajaffer
marked this pull request as ready for review
July 31, 2026 10:18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stabilize
CachedResponseBodyTests.Copy_SingleSegmentDescription
This PR addresses flakiness in
CachedResponseBodyTests.Copy_SingleSegment.The test could intermittently fail with
System.OperationCanceledExceptionduring CI execution. The failure was determined to originate from the test implementation rather than theCachedResponseBodyproduction code.The test uses a shared
CancellationTokenSourcewith a 5-second timeout for both the producer and consumer operations. Under normal execution the copy and read operations complete successfully. However, under heavy CI load or thread-pool contention, the timeout can expire while the operations are still making forward progress. When this occurs, eitherPipeReader.ReadAsync(...)orCachedResponseBody.CopyToAsync(...)observes cancellation and throwsOperationCanceledException, causing the test to fail despite the underlying functionality behaving correctly.To make the test more resilient, timeout-driven cancellation has been removed from the copy and receive operations and replaced with an explicit hang guard using
Task.WaitAsync(...). This preserves protection against hangs while allowing valid in-flight work to complete regardless of temporary scheduling delays.The updated implementation explicitly:
TimeoutExceptioninstead of injecting cancellation into otherwise healthy operations.With these changes in place, the test no longer depends on a timeout-based cancellation mechanism and is resilient to transient CI scheduling delays.
Validation / Investigation
As part of the investigation:
CachedResponseBody.CancellationTokenSourcewas identified as the source of the intermittentOperationCanceledException.Task.WaitAsync(...).While the issue is timing-dependent and primarily manifests under CI contention, the updated implementation removes the cancellation race entirely by allowing the producer and consumer to complete naturally while enforcing an external completion deadline.
Changes
CancellationTokenSourceusage from producer and consumer operations.CancellationToken.None.Task.WaitAsync(...)hang-guard protection.Fixes #61670.