Skip to content

Fix response body logging under debugger - #7678

Merged
evgenyfedorov2 merged 1 commit into
dotnet:mainfrom
Rimobul:lsokolovsky/issue-7649
Aug 4, 2026
Merged

Fix response body logging under debugger#7678
evgenyfedorov2 merged 1 commit into
dotnet:mainfrom
Rimobul:lsokolovsky/issue-7649

Conversation

@Rimobul

@Rimobul Rimobul commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

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

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.
@Rimobul

Rimobul commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

@Rimobul please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@dotnet-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@dotnet-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@dotnet-policy-service agree company="Microsoft"

Contributor License Agreement

@Rimobul Rimobul closed this Aug 4, 2026
@Rimobul Rimobul reopened this Aug 4, 2026
@Rimobul

Rimobul commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

@dotnet-policy-service agree company="Microsoft"

Rimobul

This comment was marked as off-topic.

@Rimobul
Rimobul marked this pull request as ready for review August 4, 2026 13:17
@Rimobul
Rimobul requested a review from a team as a code owner August 4, 2026 13:17
Copilot AI review requested due to automatic review settings August 4, 2026 13:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Zero as the “cancel immediately” test-only timeout, preserving Timeout.InfiniteTimeSpan behavior under debugger attachment.
  • Add regression coverage ensuring response content remains readable after logging for both seekable and non-seekable streams, and with/without LoadIntoBufferAsync (mimicking HttpCompletionOption.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
evgenyfedorov2 merged commit 5e92e76 into dotnet:main Aug 4, 2026
7 checks passed
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.

InvalidOperationException while using AddExtendedHttpClientLogging

3 participants