-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Add additional close statuses in ManagedWebSocket #83827
Conversation
Tagging subscribers to this area: @dotnet/ncl Issue DetailsAdd ServiceRestart (1012), TryAgainLater (1013), and BadGateway (1014) to the list of Fixes Issue #82602 DescriptionThe current implementation of This means that things like Customer ImpactLost information and ragged closing of a web socket when a server-side or proxy closes because of any of the previously rejected values:
This codes are documented here and here as IANA registered and in the Mozilla docs RegressionNo TestingAdded test cases for all three to new WebSocketCloseTests.cs file with no regressions in current tests. RiskThis does not change the public enum of Package authoring signed off?N/A
|
This replaces #83713 |
@wfurt and @CarnaViire I have redone this without the public enum change. Let me know if there's a better test (I don't know the WebSockets protocol at all, so I didn't build up native packets, sorry). |
src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/WebSocketCloseStatus.cs
Outdated
Show resolved
Hide resolved
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. thanks @IDisposable
We could make the extra codes private static const
inside of ManagedWebSocket.cs
but I don't have strong feelings about it. The extra comment seems sufficient to me.
That's an interesting idea @wfurt. Looks like doing the |
I would wait for feedback from others... |
src/libraries/System.Net.WebSockets/tests/WebSocketCloseTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets/tests/WebSocketCloseTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets/tests/WebSocketCloseTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets/tests/WebSocketCloseTests.cs
Outdated
Show resolved
Hide resolved
9199e46
to
d0d600e
Compare
Thanks for all the feedback @MartyIX, @wfurt, and @CarnaViire. (not sure if I need to do anything with that needs-author-action, which seems to be caused by me accepting @CarnaViire's suggestions) |
src/libraries/System.Net.WebSockets/tests/WebSocketCloseTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets/tests/WebSocketCloseTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets/tests/WebSocketCloseTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets/tests/WebSocketCloseTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.WebSockets/tests/WebSocketCloseTests.cs
Outdated
Show resolved
Hide resolved
Could you please update your branch to the current main @IDisposable ? I saw build failures that seem to be caused by branch being out of date |
Add ServiceRestart (1012), TryAgainLater (1013), and BadGateway (1014) to the list of `WebSocketCloseStatus` values and allow them to be used as valid WebSocket close statuses so we don't reject the close and discard the status description by adding them to the private `IsValueCloseStatus` method switch statement declaring them as valid `true`. These codes are documented [here as IANA registered codes](https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code) as valid server-initiated close reasons. Fixes Issue dotnet#82602
Co-authored-by: MartyIX <[email protected]>
Co-authored-by: Natalia Kondratyeva <[email protected]>
Co-authored-by: Natalia Kondratyeva <[email protected]>
Finished rename of CloseStatuses test data Renamed `closeStatusDescription` to `serverMessage` Send hello message and close status then await both responses and check they are as expected. This necessitated switching to the `ReceiveAsync` that accepts an `ArraySegment`. Explicitly typed `var`s Inlined helper methods (for clarity)
Swapping back to a distinct and more appropriately named variable for the `closeStatusDescription` Co-authored-by: Natalia Kondratyeva <[email protected]>
Co-authored-by: Natalia Kondratyeva <[email protected]>
Renamed local `serverMessage` back to `closeStatusDescription` per PR feedback. Co-authored-by: Natalia Kondratyeva <[email protected]>
Rebased to current main, updated the commit messages and added the remaining changes to address the PR comments.
5bb95d3
to
1633968
Compare
I've addressed all the PR comments and rebased to current main, but it won't build on my machine anymore... doing a Full build now to see if things will work, but figured I could push up and let the CI try, I get this when building the .SLN in the directory (worked before today):
|
Yeah, when you rebase, it's better to rebuild everything from scratch ( |
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, thanks!
I see that CLA check is stuck (it is a known issue). UPD: it helped, but the tests will be re-run. |
Test failure is unrelated #83655 |
Thanks for the fix! Just curious, will this change get backported to .NET 6 or do I need to switch to .NET 8 to consume the fix? |
The chance of a backport is extremely low, unless there's a significant business impact. Given that currently there's only one hit, I assume you would need to switch to .NET 8 @chenxinyanc |
If, by chance, we do need a backport, I would love to learn the process to do that as well. |
Add ServiceRestart (1012), TryAgainLater (1013), and BadGateway (1014) to the list of
WebSocketCloseStatus
values and allow them to be used as valid WebSocket close statuses so we don't reject the close and discard the status description by adding them to the privateIsValueCloseStatus
method switch statement declaring them as validtrue
.Fixes #82602
Description
The current implementation of
ManagedWebSocket
explicitly declares someWebSocketCloseStatus
values as "acceptable" reasons to close the socket. For those, the information status description is extracted and made available. For all other values, the close status is rejected and the closing information is discarded.This means that things like
BadGateway
(1014), orServiceRestart
(1012), orTryAgainLater
(1013) will be declared invalid byManagedWebSocket.IsValidCloseStatus
and thus not handled cleanly even though they could happen after a web socket is completely setup. These codes are documented here as valid server-initiated close reasons.Customer Impact
Lost information and ragged closing of a web socket when a server-side or proxy closes because of any of the previously rejected values:
This codes are documented here and here as IANA registered and in the Mozilla docs
Regression
No
Testing
Added test cases for all three to new WebSocketCloseTests.cs file with no regressions in current tests.
Risk
This does not change the public enum of
WebSocketCloseStatus
as we don't want to invoke public review and the values are not mentioned in the RFC.Package authoring signed off?
N/A