Open tvone-timmoore opened 3 years ago
Tagging subscribers to this area: @dotnet/ncl See info in area-owners.md if you want to be subscribed.
Author: | tvone-timmoore |
---|---|
Assignees: | - |
Labels: | `area-System.Net`, `untriaged` |
Milestone: | - |
That's because the data is sent with WebSocketMessageType.Text
, for which we check UTF-8 validity. 0xFF is not a valid UTF-8 character. If you need to send 0xFF for some reason, you can do so with WebSocketMessageType.Binary
Thanks CarnaVire, I thought as well that it might be a internal check but didn't want to jump to any conclusions.
We can't change or send as Binary as the data being returned from devices out in the field that have an unset value. It is still text but ASCII in some cases. We have to deal with older devices and code that is never going to be updated.
If that is the case then I believe the internal UTF-8 check should be optional, or is not required as:
At present I have to use WebSocketSharp-core as this works ok, I would like to use the native versions where possible. We are migrating our apps to .NET 5 then to multiple platforms with Uno and found this when trying to use the native ClientWebSocket.
the internal UTF-8 check should be optional, or is not required
It's actually required by the websocket specification: https://datatracker.ietf.org/doc/html/rfc6455
Text
The "Payload data" is text data encoded as UTF-8. Note that a
particular text frame might include a partial UTF-8 sequence;
however, the whole message MUST contain valid UTF-8. Invalid
UTF-8 in reassembled messages is handled as described in
Section 8.1.
8.1. Handling Errors in UTF-8-Encoded Data
When an endpoint is to interpret a byte stream as UTF-8 but finds
that the byte stream is not, in fact, a valid UTF-8 stream, that
endpoint MUST _Fail the WebSocket Connection_. This rule applies
both during the opening handshake and during subsequent data
exchange.
Thanks stephentoub, yes I've read the spec :) fun times, but that is not helpful in the real world, which is why I believe if the check could be made optional then that would be very helpful.
Rightly or wrongly other WebSocket implementations do not appear to be enforcing this check.
I suppose it depends on who does the checks, as I have to decode the bytes with UTF-8 then it's kind of saying that I should be doing the check and closing the connection?
Triage: Might be a good idea to enable interop. It would be nice to see if there is higher demand for such feature / option.
We have a simple text based CLI over WebSockets and sending a command results in multiple packets being returned. It appears that when awaiting ClientWebSocket.ReceiveAsync packets that have 0xFF's in the payload are causing an WebSocketExecption Aborted exception.
From WireShark
Working packet:
Packet causing ClientWebSocket to throw WebSocketExecption
NOTE: The remaining packets after this one have been sent ok and I can see them in the WireShark.
Configuration
.NET 5 WPF application Windows 10 64bit - Version 10.0.19043 Build 19043 Microsoft Visual Studio Enterprise 2019 - Version 16.10.2
.NET SDK (reflecting any global.json): Version: 5.0.301 Commit: ef17233f86
Runtime Environment: OS Name: Windows OS Version: 10.0.19043 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\5.0.301\
Host (useful for support): Version: 5.0.7 Commit: 556582d964
StackTrace:
Other information
WebSocketSharp-core works correctly and does not abort with same payload.
Additional issue
Why Oh Why has ClientWebSocket been sealed it meant that I could not try fix this by pre-processing the data before it was processed by ClientWebSocket handlers!