-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Fix ClientWebSocket hang with HttpVersionPolicy.RequestVersionOrHigher by correcting operator precedence #116817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…r by correcting operator precedence Co-authored-by: CarnaViire <3184057+CarnaViire@users.noreply.github.com>
ClientWebSocket.Connect
hangs indefinitely if using HttpVersionPolicy.RequestVersionOrHigher
on wss connections
src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.Http2.cs
Outdated
Show resolved
Hide resolved
… for proper HTTP/2 validation Co-authored-by: CarnaViire <3184057+CarnaViire@users.noreply.github.com>
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@MihaZupan PTAL? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change looks correct, but my preference would still be that we update the version selection logic to something like MihaZupan@97ca466 because it's currently unreadable.
/azp run runtime-libraries-coreclr outerloop |
Azure Pipelines successfully started running 1 pipeline(s). |
Tagging subscribers to this area: @dotnet/ncl |
@MihaZupan Of course. It was the plan initially (+ expanding the test coverage etc), but I decided it doesn't have to block the actual bugfix, and can be done as a follow-up. Esp. given we could get some help with the bugfix 😜 |
Outerloop test failures are unrelated |
Summary
This PR fixes an issue where
ClientWebSocket.Connect
hangs indefinitely when usingHttpVersionPolicy.RequestVersionOrHigher
withHttpVersion.Version11
on WSS connections.Root Cause
The issue was in the operator precedence of the conditional logic at lines 80-81 in
WebSocketHandle.Managed.cs
. The current logic:Was being evaluated as:
But should be:
The missing parentheses caused the logic to bypass the
!tryDowngrade
check when the second condition was true, leading to infinite retries of HTTP/2 instead of proper fallback to HTTP/1.1.Reproduction
The issue could be reproduced with:
Fix
Added parentheses to ensure the
!tryDowngrade
condition is properly evaluated for both HTTP/2 and HTTP/1.1 withRequestVersionOrHigher
scenarios.Testing
ConnectAsync_Http11WithRequestVersionOrHigher_Loopback_Success
that validates the fixFixes #111977.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
7b9794c0e7224d04a6e8345cb8e689e5
/home/REDACTED/work/runtime/runtime/artifacts/bin/testhost/net10.0-linux-Debug-x64/dotnet exec --runtimeconfig /home/REDACTED/work/runtime/runtime/artifacts/bin/System.Net.WebSockets.Client.Tests/Debug/net10.0/System.Net.WebSockets.Client.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/runtime/runtime/artifacts/bin/System.Net.WebSockets.Client.Tests/Debug/net10.0/System.Net.WebSockets.Client.Tests.deps.json /home/REDACTED/work/runtime/runtime/artifacts/bin/System.Net.WebSockets.Client.Tests/Debug/net10.0/testhost.dll --port 35729 --endpoint 127.0.0.1:035729 --role client --parentprocessid 38138 --datacollectionport 45605 --telemetryoptedin false
(dns block)8345476dd6e44d04be5703ccd90b5152
/home/REDACTED/work/runtime/runtime/artifacts/bin/testhost/net10.0-linux-Debug-x64/dotnet exec --runtimeconfig /home/REDACTED/work/runtime/runtime/artifacts/bin/System.Net.WebSockets.Client.Tests/Debug/net10.0/System.Net.WebSockets.Client.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/runtime/runtime/artifacts/bin/System.Net.WebSockets.Client.Tests/Debug/net10.0/System.Net.WebSockets.Client.Tests.deps.json /home/REDACTED/work/runtime/runtime/artifacts/bin/System.Net.WebSockets.Client.Tests/Debug/net10.0/testhost.dll --port 35729 --endpoint 127.0.0.1:035729 --role client --parentprocessid 38138 --datacollectionport 45605 --telemetryoptedin false
(dns block)9d5c5fafa5974fa294aa489c97acd9ac
echo.websocket.org
/tmp/TestWebSocketFix/bin/Debug/net10.0/TestWebSocketFix
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.