Bug 33210 - System.Net.ClientWebSocket sends incorrect close message
Summary: System.Net.ClientWebSocket sends incorrect close message
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-08-18 19:14 UTC by Nicholas Ventimiglia
Modified: 2017-04-03 12:49 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Nicholas Ventimiglia 2015-08-18 19:14:36 UTC
I am the developer of Websocket.Portable on Github / nuget and the Realtime.co
websocket platform api for Xamarin. Currently the ClientWebSocket is sending
close messages at incorrect times. Moreover, I have identical code running on
standard dotnet which runs fine.

Websocket.Portable :
https://github.com/NVentimiglia/WebSocket.Portable

Realtime Xamarin 
https://github.com/NVentimiglia/Realtime.Xamarin

To replicate you should :

- Download Realtime.Xamarin
https://accounts.realtime.co/signup/

(Sorry my bug relates to chunking, and its easier to just test against a free
hosted service)

- Acquire a realtime application key

-Add an application key here (free)

https://github.com/NVentimiglia/Realtime.Xamarin/blob/master/Samples/Xamarin/Realtime.Xamarin/MainView.xaml.cs#L40

- Replace the Message with a call to BigChunk()
https://github.com/NVentimiglia/Realtime.Xamarin/blob/master/Samples/Xamarin/Realtime.Xamarin/MainView.xaml.cs#L394


- Run the application (I debug on Droid, so lets keep this to droid for now)

Explanation :

When sending numerous large messages the WebSocketClient will issue a 'close
frame' and end the websocket connection. This sucks.

I have identical code using non-mono (which works) here:

https://github.com/NVentimiglia/Realtime.Xamarin/tree/master/Tests/RealtimeDotNetTests

Other Links :

https://bugzilla.xamarin.com/show_bug.cgi?id=32575

http://forums.xamarin.com/discussion/48543/bugs-and-suggestions-for-improving-system-net-clientwebsocket?new=1
Comment 1 Bahrik 2016-05-20 12:14:30 UTC
Fix:

Open http://code.metager.de/source/xref/mono/mcs/class/System/System.Net.WebSockets/ClientWebSocket.cs

Line 277:
connection.Read (req, buffer.Array, buffer.Offset, readLength);

replace to:
var fact = 0;
while (fact < readLength)
    fact += connection.Read(buffer.Array, buffer.Offset + fact, readLength - fact);

...
Comment 2 Marek Safar 2017-04-03 12:49:48 UTC
Should be fixed in master