Help with explaining Exceptions?

May 10, 2012 at 2:15 PM

Hi Kerry, hopefully you will be able to help.

We have Android clients connecting to an Azure hosted WSS Server. We are seeing a lot of errors getting logged through the ILogger looking like this:

Unable to read data from the transport connection: Cannot access a disposed object.Object name: 'System.Net.Sockets.Socket'..SuperSocket.SocketBase.Exceptions.SocketSessionException: Unable to read data from the transport connection: Cannot access a disposed object.Object name: 'System.Net.Sockets.Socket'.. ---> System.IO.IOException: Unable to read data from the transport connection: Cannot access a disposed object.Object name: 'System.Net.Sockets.Socket'.. ---> System.ObjectDisposedException: Cannot access a disposed object.Object name: 'System.Net.Sockets.Socket'.   at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult, SocketError& errorCode)   at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)   --- End of inner exception stack trace ---   at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)   at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result)   at SuperSocket.SocketEngine.AsyncStreamSocketSession`2.OnBeginInitStream(IAsyncResult result)   --- End of inner exception stack trace ---Unable to read data from the transport connection: Cannot access a disposed object.Object name: 'System.Net.Sockets.Socket'..System.IO.IOException: Unable to read data from the transport connection: Cannot access a disposed object.Object name: 'System.Net.Sockets.Socket'.. ---> System.ObjectDisposedException: Cannot access a disposed object.Object name: 'System.Net.Sockets.Socket'.   at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult, SocketError& errorCode)   at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)   --- End of inner exception stack trace ---   at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)   at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result)   at SuperSocket.SocketEngine.AsyncStreamSocketSession`2.OnBeginInitStream(IAsyncResult result)Cannot access a disposed object.Object name: 'System.Net.Sockets.Socket'.System.ObjectDisposedException: Cannot access a disposed object.Object name: 'System.Net.Sockets.Socket'.   at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult, SocketError& errorCode)   at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)

On the surface, this looks like the server has been unable to complete reading data sent from the client due to the object disposed error. Under what circumstances could this error occur. Sadly I don't have an line numbers as this is a release build.

We are also seeing a lot of error logs like this, where we reading out the session id and closing it down:

Session: 75b35e35-feca-4419-ae76-160b9afbc08a/174.252.185.204:8399ExceptionDetails: 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.NetworkStream.EndRead(IAsyncResult asyncResult)   --- End of inner exception stack trace ---   at System.Net.Security._SslStream.EndRead(IAsyncResult asyncResult)   at SuperSocket.SocketEngine.AsyncStreamSocketSession`2.OnStreamEndRead(IAsyncResult result)

Are these were the client could have terminated the connection without using the websocket protocol (by unpluging a network cable of wlaking out of wi-fi reach)??

We are currently using build 73081 of SuperSocket and build 73082 of SuperWebSockets.

Thanks

Coordinator
May 10, 2012 at 2:24 PM

I think you can ignore those exceptions which should be throw when socket is closed. The latest SuperWebSocket should have ignore them.

May 10, 2012 at 2:42 PM

Thanks Kerry

Does this error occur under certain circumstances? The reason ask is that we have only just started to get these exceptions.

Can you point me to the code change I would need to make to implement the change in my copy of the code so that SuperWebSocket ignores?

We are waiting until SuperWebSocket has the following in it before we upgrade:

  • No Log4Net dependency at all
  • ILogger interface that supports the session being passed back.
  • Ability to use configure the certificate using a X509Certificate from the store rather than a file based one.

I've mentioned these to you before and I think they are all in v1.5 SuperSocket? We are just waiting on them coming through to SuperWebSocket.

May 10, 2012 at 3:06 PM

OK, I've had a browse through the mainline SuperSocket code and really liking the look of it! I'm going to implement the use of IsIgnorableException in my version too.

However, it looks like the OnBeginInitStream method doesn't have the check in it's catch block - should it???

private void OnBeginInitStream(IAsyncResult result)
        {
            var sslStream = result.AsyncState as SslStream;

            try
            {
                sslStream.EndAuthenticateAsServer(result);
            }
            catch (Exception e)
            {
                AppSession.Logger.Error(e);
                this.Close(CloseReason.SocketError);
                return;
            }

            m_Stream = sslStream;
        }

Thanks for all your work on these implementations Kerry.

 

Coordinator
May 10, 2012 at 3:34 PM

Oh sorry, I think the exceptions throw in this place should be caught.

The exception probably should be throw when the client failed to do tls/ssl handshake? There is no this kind exception throw in my test cases.

Coordinator
May 10, 2012 at 3:39 PM
  • No Log4Net dependency at all
  • ILogger interface that supports the session being passed back.
  • Ability to use configure the certificate using a X509Certificate from the store rather than a file based one

    1 and 3 have been implemented in SuperSocket 1.5. I think the 2 can in implemeted by extension method.

    I am trying to release a beta version of SuperSocket 1.5 which can be used production environment, please be patient.

  • May 11, 2012 at 7:25 AM

    HI Kerry,

    I didn't mean it to sound like a list of demands! :-) I've patched SuperSocket to cover all three anyway, but it would be nice to get all the new refactored code in too, so we are eagerly awaiting the new version.

    Once you have a stable v1.5 SuperSocket, do you envisage it SuperWebSocket taking long to implement v1.5?

    Thanks

    Coordinator
    May 11, 2012 at 7:31 AM

    Yes, of couse.

    The code of SuperWebSocket in future folder is based on SuperSocket 1.5.