statianzo / Fleck

C# Websocket Implementation
MIT License
2.29k stars 583 forks source link

Error while closing socket connection #105

Open saileshp opened 10 years ago

saileshp commented 10 years ago

Following is the error I got.in Fleck 0.9.7:

System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult) at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult) --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult) at System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endMethod, TaskCompletionSource`1 tcs)

saileshp commented 10 years ago

can i know what can be the cause for such error , as my socket regularly gets hang by this exception. Can u provide any work around for it.

statianzo commented 10 years ago

I'm not sure of the cause. If you detect a pattern, please share it.

josteink commented 10 years ago

I've taken the stock ConsoleApp Server implementation and tweaked it to use WSS and a local cert-file for "localhost" (yes, really, don't ask).

Until mediated, this is causing some certificate trust-issues in browsers, which I suspect causes them to disconnect early in the handshake process. This again causes a internal failure in QueuedStream.BeginRead:

IOException: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine.

The stack-trace looks like this:

   at System.Net.Sockets.NetworkStream.BeginRead(Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state)
   at System.Net.FixedSizeReader.StartReading()
   at System.Net.Security._SslStream.StartFrameHeader(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security._SslStream.StartReading(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security._SslStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security._SslStream.BeginRead(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback asyncCallback, Object asyncState)
   at System.Net.Security.SslStream.BeginRead(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback asyncCallback, Object asyncState)

While the cause of the failure seems reasonable, it means that the listener is now fully dead and broken and can't be reused.

It would be nice if this one failure didn't permanently kill the "server", and possibly affect other concurrent and future clients.

Note: Running Windows & Firefox, although I don't think matters too much.

Edit: Seems it's not quite dead after all. Just misjudged the output from the server-app. Not deleting, since the post includes details on how to reproduce the error-case which may or may not be useful.