Skip to content

Potential premature dispose of HTTP/2 connection in ClientWebSocket #74415

@CarnaViire

Description

@CarnaViire

I've found very suspicious code while looking at ClientWebSocket, I didn't try to create a repro yet, but it should be easy to do so.

TL;DR: I suspect if you try to use WebSocket with custom security options like Credentials or RemoteCertificateValidationCallback, it will result in premature HTTP/2 connection disposal, so the WebSocket will not be usable.

The code that decides whether WS should dispose the message handler after use does that regardless of HTTP version

if (options.Credentials == null &&
!options.UseDefaultCredentials &&
options.Proxy == null &&
options.Cookies == null &&
options.RemoteCertificateValidationCallback == null &&
(options._clientCertificates?.Count ?? 0) == 0)
{
disposeHandler = false;

Disposing the handler after the Upgrage request is totally ok in HTTP/1.1 case, because the connection is removed from the HttpConnectionPool. But for HTTP/2 case, the connection stays in the pool, as only one stream is used for a WebSocket and other streams can be used for HTTP requests.

So, as the code follows, after an Extended Connect call and creation of a WebSocket, the handler will get disposed, which will result in HTTP/2 connections in the pool being disposed, which will result in a closed HTTP/2 stream and an aborted WebSocket -- unless I miss something.

Could you please check out this scenario @greenEkatherine?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions