Skip to content
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

Adding stream timeouts #492

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

michaldobrodenka
Copy link

Sometimes on poor connections I'm experiencing Thread pool deadlock, it seems like EndRead in SSL stream waits forever. Hope this will improve situation. I have seen similar problem with connect also.

Try/catch around Dispose was necessary on iOS with Xamarin, if stream was already Disposed (app went foreground), Dispose crashed app with exception.

"Threadpool worker" tid=0x0xa4767430 this=0x0xaaf8e950 thread handle 0x578 state : waiting on 0x60e : Sem owns ()
at <unknown> <0xffffffff>
at (wrapper managed-to-native) System.Threading.Monitor.Enter (object) <0xffffffff>
at WebSocketSharp.WebSocket.close (WebSocketSharp.CloseEventArgs,bool,bool,bool) <0x00047>
at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object_byte_byte_byte (object,intptr,intptr,intptr) <0xffffffff>


"Threadpool worker" tid=0x0xa84ff430 this=0x0xaba6bd40 thread handle 0x6f8 state : waiting on 0x72a : Event owns ()
at <unknown> <0xffffffff>
at (wrapper managed-to-native) System.Threading.WaitHandle.WaitOne_internal (System.Threading.WaitHandle,intptr,int,bool) <0xffffffff>
at System.Threading.WaitHandle.WaitOne () <0x0006f>
at Mono.Security.Protocol.Tls.RecordProtocol.EndReceiveRecord (System.IAsyncResult) <0x0008b>
at Mono.Security.Protocol.Tls.RecordProtocol.ReceiveRecord (System.IO.Stream) <0x0002f>
at Mono.Security.Protocol.Tls.SslClientStream.SafeReceiveRecord (System.IO.Stream,bool) <0x0002b>
at Mono.Security.Protocol.Tls.SslClientStream.OnNegotiateHandshakeCallback (System.IAsyncResult) <0x00037>
at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (System.IAsyncResult) <0x0009f>
at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object (object,intptr,intptr,intptr) <0xffffffff>


"Threadpool worker" tid=0x0xa60ff430 this=0x0xaba687a0 thread handle 0xbe7 state : waiting on 0xbe8 : Event owns ()
at <unknown> <0xffffffff>
at (wrapper managed-to-native) System.Threading.WaitHandle.WaitOne_internal (System.Threading.WaitHandle,intptr,int,bool) <0xffffffff>
at System.Threading.WaitHandle.WaitOne () <0x0006f>
at Mono.Security.Protocol.Tls.RecordProtocol.EndReceiveRecord (System.IAsyncResult) <0x0008b>
at Mono.Security.Protocol.Tls.RecordProtocol.ReceiveRecord (System.IO.Stream) <0x0002f>
at Mono.Security.Protocol.Tls.SslClientStream.SafeReceiveRecord (System.IO.Stream,bool) <0x0002b>
at Mono.Security.Protocol.Tls.SslClientStream.OnNegotiateHandshakeCallback (System.IAsyncResult) <0x00037>
at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (System.IAsyncResult) <0x0009f>
at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object (object,intptr,intptr,intptr) <0xffffffff>


"Threadpool worker" tid=0x0xaa9ff430 this=0x0xaf662c10 thread handle 0x84e state : waiting on 0x8d0 : Event owns ()
at <unknown> <0xffffffff>
at (wrapper managed-to-native) System.Threading.WaitHandle.WaitOne_internal (System.Threading.WaitHandle,intptr,int,bool) <0xffffffff>
at System.Threading.WaitHandle.WaitOne () <0x0006f>
at Mono.Security.Protocol.Tls.SslStreamBase.EndRead (System.IAsyncResult) <0x0009f>
at System.Net.Security.SslStream.EndAuthenticateAsClient (System.IAsyncResult) <0x00047>
at System.Net.Security.SslStream.AuthenticateAsClient (string,System.Security.Cryptography.X509Certificates.X509CertificateCollection,System.Security.Authentication.SslProtocols,bool) <0x0006b>
at WebSocketSharp.WebSocket.setClientStream () <0x002e7>
at WebSocketSharp.WebSocket.doHandshake () <0x0001b>
at WebSocketSharp.WebSocket.connect () <0x000db>
at (wrapper runtime-invoke) <Module>.runtime_invoke_bool__this__ (object,intptr,intptr,intptr) <0xffffffff>


"Threadpool worker" tid=0x0xa97ff430 this=0x0xaba68b10 thread handle 0xadc state : waiting on 0xae8 : Event owns ()
at <unknown> <0xffffffff>
at (wrapper managed-to-native) System.Threading.WaitHandle.WaitOne_internal (System.Threading.WaitHandle,intptr,int,bool) <0xffffffff>
at System.Threading.WaitHandle.WaitOne () <0x0006f>
at Mono.Security.Protocol.Tls.SslStreamBase.EndRead (System.IAsyncResult) <0x0009f>
at System.Net.Security.SslStream.EndAuthenticateAsClient (System.IAsyncResult) <0x00047>
at System.Net.Security.SslStream.AuthenticateAsClient (string,System.Security.Cryptography.X509Certificates.X509CertificateCollection,System.Security.Authentication.SslProtocols,bool) <0x0006b>
at WebSocketSharp.WebSocket.setClientStream () <0x002e7>
at WebSocketSharp.WebSocket.doHandshake () <0x0001b>
at WebSocketSharp.WebSocket.connect () <0x000db>
at (wrapper runtime-invoke) <Module>.runtime_invoke_bool__this__ (object,intptr,intptr,intptr) <0xffffffff>

michaldobrodenka and others added 5 commits September 25, 2018 15:01
- Adding try/catch around stream.Dispose() because with SSL streams in Mono stream can be sometimes already disposed and Dispose throws exception, crashing the app
…der and weaker android devices (probably code was run synchronously and code around is not really ready for it). Some other fixes in server code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants