Skip to content

Conversation

@ManickaP
Copy link
Member

@ManickaP ManickaP commented Jul 1, 2025

Use loopback server since some of the validation happens when serializing to the wire which is after establishing the connection.

Fixes #117198

Compare without whitespace.

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Fix the new header test by sending the request over a loopback server so that header serialization happens on the wire.

  • Wrap the existing test logic in LoopbackServerFactory.CreateClientAndServerAsync with separate client/server callbacks.
  • Introduce a TaskCompletionSource<bool> to coordinate whether the server should accept the connection.
  • Change CookieContainer.Add(new Uri(uri), …) to the overload CookieContainer.Add(uri, …).
Comments suppressed due to low confidence (3)

src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.cs:2175

  • Consider specifying TaskCreationOptions.RunContinuationsAsynchronously when creating the TaskCompletionSource to avoid potential deadlocks from synchronous continuations.
            TaskCompletionSource<bool> acceptConnection = new TaskCompletionSource<bool>();

src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.cs:2205

  • Use TrySetResult instead of SetResult to prevent an InvalidOperationException if the TaskCompletionSource is completed more than once.
                    acceptConnection.SetResult(false);

src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.cs:2177

  • Ensure the TaskCompletionSource is completed in all code paths (including unexpected exceptions) by adding a catch-all or finally block inside the client lambda, otherwise the server callback may hang waiting for the result.
            await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>

Copy link
Member

@MihaZupan MihaZupan left a comment

Choose a reason for hiding this comment

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

Thanks

Copy link
Member

@CarnaViire CarnaViire left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

@ManickaP ManickaP merged commit ddff3a3 into dotnet:main Jul 3, 2025
82 of 87 checks passed
@ManickaP ManickaP deleted the fix-header-test branch July 3, 2025 07:30
@github-actions github-actions bot locked and limited conversation to collaborators Aug 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SendAsync_RequestWithDangerousControlHeaderValue_ThrowsHttpRequestException fails with QUIC protocol error

3 participants