[release/8.0][browser] WebSocket works differently depending on if we look up its state or not #99673
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport of #99612, #99685 and (partially) #96618.
Fixes #99545.
Contributes to #96359
Description
We enhanced state change propagation - managed code does not get information about the socket having closed till all the messages are received. This prevents from losing messages (and throwing
Unhandled exception rendering component: The WebSocket is in an invalid state ('Closed') for this operation. Valid states are: 'Open, CloseSent'
).Customer Impact
The use case is quite narrow, user needs to connect to ws, send a message from server to client that is not immediately received and close the connection before the client receives it. If they check the ws state in between closing the socket and receiving the message, they will get an exception and will not be able to receive the message. This PR fixes it and they will be able to keep receiving the messages till the buffer is cleaned.
Regression
No.
Testing
This PR adds unit tests.
Risk
Small, it impacts only one specific use-case.