SuperWebSocketWeb sample - Push data from WebSocket

Oct 12, 2011 at 8:56 AM

Hello,

We are using SuperWebSocket implementation for a Statistics Call Center application. After starting to simulate some real life scenarios, we went into a point where client connection will always close at the very beginning. More clients that will listen, more chances to have them disconnected after a few minutes. 

Trying to locate the source of this problem, we were using SuperWebSocketWeb sample to push some raw data (just a small string) to the clients at a high rate (ten times per second). We notice that a close connection event occurs in less than a minute using Google Chrome 14 and Firefox 7 browsers.

Looking in System.Net.Trace.log from SuperWebSocketWeb sample, we noticed this log entries at the point where connection was closed:

Verbose: 0 : Data from Socket#44624228::Send
Verbose: 0 : Socket#44624228::Shutdown(Both#2)
...
Verbose: 0 : Socket#44624228::Send()
Verbose: 0 : Exiting Socket#44624228::Shutdown() 
...
Error: 0 : [6544] Exception in the Socket#44624228::Send - An established connection was aborted by the software in your host machine
Verbose: 0 : [4440] Socket#44624228::Close()
Verbose: 0 : [4440] Socket#44624228::Dispose()
...

What do you think it is causing this problem?

I can send you the small changes I've made to SuperWebSocketWeb sample if it helps you to reproduce the problem, but basically we are pushing small raw data to the clients. Even if we are pushing at a slower rate, the same situation will occur at some point.

Thank you,

rzv

Coordinator
Oct 12, 2011 at 8:59 AM

Please send me the piece of code you have changed!

Oct 12, 2011 at 9:19 AM
Edited Oct 12, 2011 at 9:20 AM

Hello Kerry,

Here is the link to the modified SuperWebSocketWeb sample: https://skydrive.live.com/?cid=ba2a6497d801c89a&sc=documents&nl=1&uc=1&id=BA2A6497D801C89A%21106#

I have commented out all the things we do not need for this test like secure connection and messages sent by the clients. After connecting to the server, raw data is pushed at high rate and user will be disconnected at some early point. I hope you'll easily reproduce the problem by yourself.

Thank you,

rzv

Oct 12, 2011 at 12:12 PM

Hello again,

Maybe it helps. We have found that when the client is closed, the following function is called in SuperSocket\SocketEngine\AsyncSocketSession.cs:

 

public void ProcessReceive(SocketAsyncEventArgs e)
{
    // check if the remote host closed the connection
    if (e.BytesTransferred <= 0)
    {
        Close(CloseReason.ClientClosing);
        return;
    }
    ...
}

At that point, e.BytesTransferred == 0, so Close() function is called.

rzv

 

Coordinator
Oct 12, 2011 at 1:44 PM

If so, the connections were closed from client (browser).

Oct 12, 2011 at 2:00 PM
Edited Oct 12, 2011 at 2:39 PM

Hello Kerry,

I understand this. The question still remains: why is this happening? Modified SuperWebSocketWeb test case is a simple one and it should work without too much troubles. We have reproduced the same behavior on different machines and I am sure it is easy to reproduce by everyone. I can not understand why the client is closing the connection, no matter of the used browser.

Do you know if there is any SuperWebSocket sample that simulates heavy traffic from server to clients and is working smoothly?

Thank you,

rzv

UPDATE:

A simple C# client is communicating without any problems with SuperWebSocket server, so it could be the browser itself that cause this mess, as you said.

UPDATE 2:

Same problem with C# client, same kind of error. Connection with the client is closed at some point, but not so early (it took 10 minutes).

Oct 12, 2011 at 2:54 PM
Edited Oct 12, 2011 at 3:01 PM

Hello again,

I hope I do not bother you, I just need to identify the problem. Below there is a C# client test case where the same problem can be reproduced (if you use the above modified SuperWebSocketWeb sample). Here are the two projects: https://skydrive.live.com/?cid=ba2a6497d801c89a&sc=documents&uc=2&id=BA2A6497D801C89A%21106 .

1. SuperWebSocketTest

This is a modified version of your test and the only change is we will not close connection anymore in WebSocketClientTest.cs.

public void ConnectionTest()
{
    // Here we have added path to the SuperWebSocketWeb server
    WebSocket webSocketClient = new WebSocket("ws://192.168.1.101:2011/sample", "basic");
            
    ...

    //if(!m_OpenEvent.WaitOne(1000))
    //    Assert.Fail("Failed to open session ontime");

    //webSocketClient.Close();

    //if (!m_CloseEvent.WaitOne(1000))
    //    Assert.Fail("Failed to close session ontime");
}

2. TestWebSocket

This is just a console client that connects to the SuperWebSocketWeb server (really basic).

class Program
{
    static void Main(string[] args)
    {
        WebSocketClientTest test = new WebSocketClientTest();
        test.ConnectionTest();
        Console.ReadLine();
    }
}

In this test scenario, the connection was closed in WebSocket.cs :

void ProcessReceiveData(byte[] buffer, int offset, int length)
{
    ...
    if (loofForByte == m_StartByte)
    {
        EnsureCloseSocket(true);
        return;
    }
    ....
}

Conclusion is that the problem appears not only in browser, but also in a console client.

Thank you,

rzv 

Coordinator
Oct 12, 2011 at 3:18 PM

Let me write a test case for it.

Coordinator
Oct 12, 2011 at 3:25 PM

If so, in your test

there are two cases:

close from client

close from server

?

Oct 12, 2011 at 3:34 PM
Edited Oct 12, 2011 at 3:34 PM

Hello,

The close event is raised from the client due to the call of this function:

EnsureCloseSocket(true);

The client was run in Debug mode on a different machine than the server and this is how we catch where it was closed.

I'll be offline from now, but we'll check more tomorrow.

rzv

Coordinator
Oct 12, 2011 at 4:26 PM

Sorry, I cannot produce this issue, I changed the code in Global.asax.cs to test like the code below:

private List<WebSocketSession> m_Sessions = new List<WebSocketSession>();
        private List<WebSocketSession> m_SecureSessions = new List<WebSocketSession>();
        private object m_SessionSyncRoot = new object();
        private object m_SecureSessionSyncRoot = new object();
        private Timer m_SecureSocketPushTimer;

        void Application_Start(object sender, EventArgs e)
        {
            LogUtil.Setup();
            StartSuperWebSocketByConfig();
            //StartSuperWebSocketByProgramming();
            var ts = new TimeSpan(0, 0, 0, 0, 100);
            m_SecureSocketPushTimer = new Timer(OnSecureSocketPushTimerCallback, new object(), ts, ts);
        }

        void OnSecureSocketPushTimerCallback(object state)
        {
            lock (m_SessionSyncRoot)
            {
                m_Sessions.ForEach(s => s.SendResponseAsync("Push data from WebSocket. Current Time: " + DateTime.Now));
            }
        }

And I opened 3 tabs to test, and run longer than 10 minutes, but no connection dropped.

Could you tell me your mail box? I can send you the socket trace log file (8 MB). My mail address is kerry-jiang@hotmail.com.

Which OS are you using? Or any other anti-virus, network guard software is running?

 

Oct 13, 2011 at 12:23 PM
Edited Oct 13, 2011 at 12:24 PM

Hello Kery,

We are using development machines (Windows 7 Enterprise, SP1) with firewalls turned off, no antivirus or network guard.  Pretty strange that this problem appears only on our side. Today we have also made the same test with Microsoft WebSockets prototype (http://html5labs.interoperabilitybridges.com/prototypes/websockets/websockets/info) and connections have not been dropped at all. So there is no browser/computer limitation here. Using SuperWebSocket, clients like Firefox, IE and Chrome decides at some point to close the connection. We will still keep using SuperWebSockets and try to isolate the problem.

Thank you for your time,

rzv

Coordinator
Oct 13, 2011 at 3:09 PM

We have same environment.

It seems I need to add a test case to cover this case.