Fix response body logging under debugger - #7678
Merged
Merged
Conversation
Fixes dotnet#7649 Treat only TimeSpan.Zero as an immediate test timeout. This preserves the infinite timeout used while debugging, allowing the response body to be logged without leaving the content stream consumed. Add regression coverage for seekable and non-seekable streams, with and without response content buffering.
Contributor
Author
|
Contributor
Author
|
@dotnet-policy-service agree company="Microsoft" |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a regression in Microsoft.Extensions.Http.Diagnostics where response body logging could cancel immediately when a debugger is attached (because Timeout.InfiniteTimeSpan is negative), which could lead to the response content stream being left in an unreadable/consumed state for callers.
Changes:
- Update the response-body read-timeout logic to treat only
TimeSpan.Zeroas the “cancel immediately” test-only timeout, preservingTimeout.InfiniteTimeSpanbehavior under debugger attachment. - Add regression coverage ensuring response content remains readable after logging for both seekable and non-seekable streams, and with/without
LoadIntoBufferAsync(mimickingHttpCompletionOption.ResponseContentRead).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test/Libraries/Microsoft.Extensions.Http.Diagnostics.Tests/Logging/HttpResponseBodyReaderTest.cs | Adds combinatorial regression test validating body logging under debugger doesn’t consume/break the response stream (seekable/non-seekable, buffered/unbuffered). |
| src/Libraries/Microsoft.Extensions.Http.Diagnostics/Logging/Internal/HttpResponseBodyReader.cs | Fixes timeout comparison so Timeout.InfiniteTimeSpan under debugger no longer triggers immediate cancellation. |
evgenyfedorov2
approved these changes
Aug 4, 2026
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.
Fixes #7649
Treat only TimeSpan.Zero as an immediate test timeout. This preserves the infinite timeout used while debugging, allowing the response body to be logged without leaving the content stream consumed.
Add regression coverage for seekable and non-seekable streams, with and without response content buffering.
Microsoft Reviewers: Open in CodeFlow