sta / websocket-sharp

A C# implementation of the WebSocket protocol client and server
http://sta.github.io/websocket-sharp
MIT License
5.72k stars 1.66k forks source link

Xamarin.iOS Application crash - Mono SslStream throws an exception in Dispose() #337

Open michaldobrodenka opened 7 years ago

michaldobrodenka commented 7 years ago

Sometimes when changing wifi/4G on iPhone app crashes because in WebSocket.cs in releaseClientResources is called _stream.Dispose(); and Dispose throws an Exception.

Swallowing exception helped. I don't know how to handle it better.

Unable to write data to the transport connection: The socket has been shut down. (System.IO.IOException) at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, System.Int32 offset, System.Int32 size) [0x000e8] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.121/src/mono/mcs/class/referencesource/System/net/System/Net/Sockets/NetworkStream.cs:602 at Mono.Net.Security.MobileAuthenticatedStream.InnerFlush () [0x00011] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.121/src/mono/mcs/class/System/Mono.Net.Security/MobileAuthenticatedStream.cs:562 at Mono.Net.Security.MobileAuthenticatedStream.InnerWrite () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.121/src/mono/mcs/class/System/Mono.Net.Security/MobileAuthenticatedStream.cs:556 at Mono.Net.Security.AsyncProtocolRequest.ProcessOperation (Mono.Net.Security.AsyncOperationStatus status) [0x0006b] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.121/src/mono/mcs/class/System/Mono.Net.Security/AsyncProtocolRequest.cs:267 at Mono.Net.Security.AsyncProtocolRequest.ProcessOperation () [0x0000d] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.121/src/mono/mcs/class/System/Mono.Net.Security/AsyncProtocolRequest.cs:218 at Mono.Net.Security.AsyncProtocolRequest.StartOperation () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.121/src/mono/mcs/class/System/Mono.Net.Security/AsyncProtocolRequest.cs:199 --- inner exception --- The socket has been shut down (System.Net.Sockets.SocketException) at System.Net.Sockets.Socket.Send (System.Byte[] buffer, System.Int32 offset, System.Int32 size, System.Net.Sockets.SocketFlags socketFlags) [0x0002a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.121/src/mono/mcs/class/System/System.Net.Sockets/Socket.cs:2383 at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer, System.Int32 offset, System.Int32 size) [0x000b4] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.121/src/mono/mcs/class/referencesource/System/net/System/Net/Sockets/NetworkStream.cs:591 ... WebSocket.cs releaseClientResources

ilsnk commented 2 years ago

hello friend, did you somehow solve this problem?

michaldobrodenka commented 2 years ago

Hi, to be fair I don't know. I have forked websocket-sharp and keep fixing it. On my github, there is a fork, but I have bunch of fixes not pushed to github, only in my private repo in project I'm working on. I don't pull changes, at least for 4 years. It's difficult because of non standard c# formatting (I get it - mono develop) and no commit messages. If you want, I can put my websocket-sharp code to github. I also made a changes to work in netcore.

michaldobrodenka commented 2 years ago

@ilsnk I've uploaded all my code, currently using to my fork in https://github.com/michaldobrodenka/websocket-sharp

Forked about 4yrs ago, fixing internally since then

ilsnk commented 2 years ago

thank you, i will definitely check it out