Skip to content

Throw on incompatible WebSocket options - #74473

Merged
MihaZupan merged 4 commits into
dotnet:mainfrom
MihaZupan:ws-throw-on-custom-options
Sep 2, 2022
Merged

Throw on incompatible WebSocket options#74473
MihaZupan merged 4 commits into
dotnet:mainfrom
MihaZupan:ws-throw-on-custom-options

Conversation

@MihaZupan

@MihaZupanMihaZupan commented Aug 24, 2022

Copy link
Copy Markdown
Member

Fixes#74415
Fixes#74416

For #74415, we now throw if HTTP/2 has been requested but a custom invoker wasn't specified.

For #74416, I added a simple check for any options that can't be honored when using a custom invoker instance, and we now throw an ArgumentException.
The only exception is the default Proxy - we don't throw if the user doesn't overwrite it (as that would impact all default use cases). Given that SocketsHttpHandler shares the same default (default proxy is used unless explicitly disabled), I don't think this is a big deal.

@ghost

Copy link
Copy Markdown

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

Issue Details

Fixes #74415
Fixes #74416

There were 3 issues around reusing the shared handler:

  1. The bug we had before 7.0 where we weren't reusing the handler unless you manually accessed ClientCertificates
  2. ClientWebSocket sets the Proxy options by default, so we don't reuse the handler unless the user manually sets Proxy back to null
  3. For H2, it's problematic that we set PooledConnectionLifetime to zero, as that means we're opening a new H2 connection for every WebSocket, throwing away all the benefits of the protocol.

I changed the logic so that we now hold 2 shared handler instances: one for "no proxy" and one for "default proxy". This resolves problem nr. 2.

To mitigate problem 3, I changed the default PooledConnectionLifetime from zero to 2 minutes, matching IHttpClientFactory's default. Ideally, we should have a DNS TTL mechanism here instead.
Are we okay with having such a non-configurable default here? This only affects HTTP/2 and has a workaround of using a custom invoker instance.
I also set EnableMultipleHttp2Connections to true on the shared handler to avoid introducing a stream limit (there is no limit if the lifetime is set to zero).

While I was making these changes, I also avoided the HttpMessageInvoker allocation for shared handlers (#70895 (comment)).

For #74416, I added a simple check for any options that can't be honored when using a custom invoker instance, and we now throw an ArgumentException.
The only exception is the default Proxy - we don't throw if the user doesn't overwrite it (as that would impact all default use cases). Given that SocketsHttpHandler shares the same default (default proxy is used unless explicitly disabled), I don't think this is a big deal.

Author:MihaZupan
Assignees:-
Labels:

area-System.Net

Milestone:-

@ghostghost assigned MihaZupanAug 24, 2022
@MihaZupan

Copy link
Copy Markdown
MemberAuthor

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@CarnaViire

Copy link
Copy Markdown
Member

It seems that outerloop hit the same issue #74450 did...

CarnaViire
CarnaViire previously approved these changes Aug 24, 2022

@CarnaViireCarnaViire left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

greenEkatherine
greenEkatherine previously approved these changes Aug 24, 2022
@MihaZupan

Copy link
Copy Markdown
MemberAuthor

@stephentoub could please take a look at this one given that it concerns client sharing/caching?
This is also a place where we could consider using HttpClient.Shared in the future.

@karelzkarelz added this to the 8.0.0 milestone Aug 30, 2022
@MihaZupan
MihaZupanforce-pushed the ws-throw-on-custom-options branch from 0722b7e to dcc51fcCompareSeptember 1, 2022 19:30
@MihaZupanMihaZupan changed the title Reuse shared invoker and throw on incompatible WebSocket optionsThrow on incompatible WebSocket optionsSep 1, 2022
@MihaZupan
MihaZupan dismissed stale reviews from greenEkatherine and CarnaViireSeptember 1, 2022 19:32

Stale

@MihaZupan

Copy link
Copy Markdown
MemberAuthor

/azp run runtime-libraries-coreclr outerloop

@MihaZupan
MihaZupan requested review from a team and stephentoubSeptember 1, 2022 19:33
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@MihaZupan

Copy link
Copy Markdown
MemberAuthor

Updated the PR to remove all of the pooling logic. This is now just adding options validation and test changes.

Comment threadsrc/libraries/System.Net.WebSockets.Client/src/Resources/Strings.resx Outdated
Comment threadsrc/libraries/System.Net.WebSockets.Client/src/Resources/Strings.resx Outdated

@stephentoubstephentoub left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Product changes LGTM

@MihaZupanMihaZupan reopened this Sep 2, 2022
@MihaZupan
MihaZupan merged commit 9ea5d2d into dotnet:mainSep 2, 2022
@MihaZupan

Copy link
Copy Markdown
MemberAuthor

/backport to release/7.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/7.0: https://github.com/dotnet/runtime/actions/runs/2981306574

steveisok pushed a commit to steveisok/runtime that referenced this pull request Sep 9, 2022
dotnet#74473 had a change where we started adding a client certificate that is not supported on apple mobile platforms. This lead to an unhandled exception in the MemberData setup of ConnectAsync_CustomInvokerWithIncompatibleWebSocketOptions_ThrowsArgumentException and resulted in an app crash.
Addresses dotnet#75307
steveisok added a commit that referenced this pull request Sep 11, 2022
…75344)
#74473 had a change where we started adding a client certificate that is not supported on apple mobile platforms. This lead to an unhandled exception in the MemberData setup of ConnectAsync_CustomInvokerWithIncompatibleWebSocketOptions_ThrowsArgumentException and resulted in an app crash.
Addresses #75307
github-actionsBot pushed a commit that referenced this pull request Sep 11, 2022
#74473 had a change where we started adding a client certificate that is not supported on apple mobile platforms. This lead to an unhandled exception in the MemberData setup of ConnectAsync_CustomInvokerWithIncompatibleWebSocketOptions_ThrowsArgumentException and resulted in an app crash.
Addresses #75307
steveisok pushed a commit that referenced this pull request Sep 12, 2022
…75423)
Backport of #75344 to release/7.0
#74473 had a change where we started adding a client certificate that is not supported on apple mobile platforms. This lead to an unhandled exception in the MemberData setup of ConnectAsync_CustomInvokerWithIncompatibleWebSocketOptions_ThrowsArgumentException and resulted in an app crash.
Addresses #75307
@ghostghost locked as resolved and limited conversation to collaborators Oct 3, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

5 participants

@MihaZupan@CarnaViire@stephentoub@greenEkatherine@karelz