Crash - Null object reference in OnMessageEvent

Mar 5, 2014 at 12:49 PM
I'm using the latest downloadable version - 0.6.26.0. This crash is particularly nasty because it can't be trapped since it's running on a background thread, so it causes the entire program to crash because of an unhandled exception.

This crash happens in the wild for various reasons -- mostly related to connectivity at the client end. The easiest way I've found to reproduce it is to setup the socket.io server to disconnect the client immediately after connection -- this is contrived, but it accurately reproduces a real problem:

Server socket.io code:
   io.sockets.on('connection', function (socket) {
      socket.disconnect();
   }
This will cause an unhandled exception to be thrown in SocketIOClient.Client in the OnMessageEvent method. The registratioNManager is null in here.

Has this been fixed in any version of the source?
Coordinator
Mar 5, 2014 at 1:01 PM
I'll have to try that out, I have not run into that sort of issue.
Could you show a representative sample of what the c# socketio4net code side looks like, and I'd be happy to review and test things out?
Mar 5, 2014 at 1:17 PM
jstott wrote:
I'll have to try that out, I have not run into that sort of issue.
Could you show a representative sample of what the c# socketio4net code side looks like, and I'd be happy to review and test things out?
The following should accurately reproduce it from a c# client using socketio4net:
socketIo = new Client(serverAddress);
socket.Connect();
If you want to connect to my server, I can 'block' your ip so that we can reproduce the disconnect as well. Any way to PM each other here?
Coordinator
Mar 5, 2014 at 2:12 PM
Connecting to your server isn't the root of the issue here, what I'd like to see is what the makeup of the socketio4net side of the code looks like.

My concern is the timing / order of the calls your making with the library could be part of the issue? At this point I assume your configuring the OnMessage event handler after you've made the call to connect, and not before? However, that isn't even included in your sample, so not sure I can help much further.

This is what I've tested from the snippet you gave - I don't see any issue at this point:

C#
public class BugRequest
    {
        Client socket;
        public void Execute()
        {
            Console.WriteLine("Starting BugDisconnect Example...");

            socket = new Client("http://127.0.0.1:3000/"); // url to the nodejs / socket.io instance

            
            socket.Connect();
        }
    }
node / socket.io server
// configure Socket.IO
var io = socketio.listen(server); // start socket.io

// ***************************************************************
//    Socket.IO Client Handlers
// ***************************************************************
io.sockets.on('connection', function (socket) {

    socket.disconnect();
});