Skip to content

Enough socket.io-event routers attached to socket causes a crash when enough clients does reconnect. #19

Description

@jtiai

When 20 or more routers are attached to socket using socket.use reconnection attempt causes unhandled errors when enough clients does reconnection simultaenously. Error doesn't appear if I attach vanilla handlers (without socket.io-events router) to socket with socket.use.

Error message:

TypeError: Uncaught, unspecified "error" event.
    at TypeError (<anonymous>)
    at Socket.EventEmitter.emit (events.js:74:15)
    at next (/home/jtiai/Code/websockets/node_modules/socket.io-events/lib/router.js:130:20)
    at step (/home/jtiai/Code/websockets/node_modules/socket.io-events/lib/router.js:188:9)
    at next (/home/jtiai/Code/websockets/node_modules/socket.io-events/lib/router.js:144:11)
    at next (/home/jtiai/Code/websockets/node_modules/socket.io-events/lib/router.js:136:15)
    at step (/home/jtiai/Code/websockets/node_modules/socket.io-events/lib/router.js:149:23)
    at Router.router.onRoute (/home/jtiai/Code/websockets/node_modules/socket.io-events/lib/router.js:191:7)
    at step (/home/jtiai/Code/websockets/node_modules/socket.io-events/lib/router.js:176:18)
    at next (/home/jtiai/Code/websockets/node_modules/socket.io-events/lib/router.js:144:11)

Number of required clients seem to vary but in my environments I get consistent results with 20 routers and 100 concurrent clients.

Steps to reproduce:

  1. start server.py with nodejs server.py
  2. start client.py with nodejs client.py
  3. Observe successful connections
  4. stop server.py
  5. start server.py again
  6. Observe errors when clients do reconnect.

server.py:

const PORT = 3000;

var sock = require('socket.io')(PORT);

sock.on('connect', function() {
  console.log('Successful connection');
});

sock.on('disconnect', function() {
  console.log('Disconnected');
});

// Create 20 individual routers and attach them to socket
for (var i=0;i < 20;i++) {
  (function (id) {
    var router = require('socket.io-events')();
    router.on('msg'+id, function(sock, next) {});
    sock.use(router);
  })(i);
}

client.py:

const PORT = 3000;

var Client = require('socket.io-client');

// Connect 100 clients
for (var i=0; i < 100; i++) {
  (function(id) {
    var sock = Client('http://localhost:'+PORT, { multiplex: false });

    sock.on('connect', function() {
      console.log('Connection %s connected', id);
    })
    sock.on('disconnect', function() {
      console.log('Connection %s disconnected', id);
    })
    sock.on('reconnect', function() {
      sock.emit('relogin', 'user-' + id);
      console.log('Connection %s reconnected', id);
    })
  })(i);
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions