Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sticky-session: worker died error TypeError: Cannot call method 'removeListener' of undefined #22

Open
Alexandrrr opened this issue Apr 10, 2015 · 4 comments

Comments

@Alexandrrr
Copy link

Hello.
I had a problem with my project. If I hold down the button F5 to reload my page, which is rendered by GET request, nodeserver is down with exception:
sticky-session: worker died
error TypeError: Cannot call method 'removeListener' of undefined

CallStack:
at httpSocketSetup (http.js:1859:10)
at Server.connectionListener (http.js:1928:3)
at Server.emit (events.js:95:17)
at process. (/var/www/producer/data/www/producer.lifeha.ru/project/node_modules/sticky-session/lib/sticky-session.js:63:14)
at process.emit (events.js:117:20)
at handleMessage (child_process.js:322:10)
at Pipe.channel.onread (child_process.js:349:11)
sticky-session: worker died

@liebo
Copy link

liebo commented Apr 20, 2015

the same problem when high concurrent connection number

@triitvn
Copy link

triitvn commented May 5, 2015

@liebo @Alexandrrr I have the same issue. I use sitcky session with socket.io. How can we setup a high-traffic websocket server?

Here is my app:

(function() {
  var admSecret, os, redis, socketPort, sticky;

  os = require('os');

  redis = require('socket.io-redis');

  sticky = require('sticky-session');

  socketPort = 3000;

  sticky(function() {
    var handler, importantNotice, io, server;

    handler = function(req, res) {
      res.writeHead(200);
      return res.end('vgws: ' + process.pid);
    };

    server = require('http').createServer(handler);

    io = require('socket.io')(server);

    io.adapter(redis({
      host: 'localhost',
      port: 6379
    }));

    io.on('connection', function(socket) {
      socket.on('important-notice', function() {
        return socket.emit('important-notice', importantNotice);
      });
    });
    return server;
  }).listen(socketPort, function() {
    console.log(process.pid);
  });

}).call(this);

Error in high traffic period

http.js:1864
  socket.removeListener('drain', ondrain);
         ^
TypeError: Cannot call method 'removeListener' of undefined
    at httpSocketSetup (http.js:1864:10)
    at Server.connectionListener (http.js:1933:3)
    at Server.emit (events.js:95:17)
    at process.<anonymous> (/home/node_modules/sticky-session/lib/sticky-session.js:63:14)
    at process.emit (events.js:117:20)
    at handleMessage (child_process.js:322:10)
    at Pipe.channel.onread (child_process.js:349:11)
sticky-session: worker died
11429

http.js:1864
  socket.removeListener('drain', ondrain);
         ^
TypeError: Cannot call method 'removeListener' of undefined
    at httpSocketSetup (http.js:1864:10)
    at Server.connectionListener (http.js:1933:3)
    at Server.emit (events.js:95:17)
    at process.<anonymous> (/home/node_modules/sticky-session/lib/sticky-session.js:63:14)
    at process.emit (events.js:117:20)
    at handleMessage (child_process.js:322:10)
    at Pipe.channel.onread (child_process.js:349:11)
sticky-session: worker died
11534
11536

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: read ECONNRESET
    at errnoException (net.js:905:11)
    at TCP.onread (net.js:559:19)
4 May 14:55:15 - [nodemon] app crashed - waiting for file changes before starting..

@Mad-Head
Copy link

Mad-Head commented May 8, 2015

Cause of error:
You tried to "server.emit ('connection', socket);" in sticky-session.js: 63 line, where: variable "socket" is undefined.

Solution: add a validation variable.

For example:

    process.on('message', function(msg, socket) {
      if (msg !== 'sticky-session:connection') return;
      if (socket) {
        server.emit('connection', socket);
      } else {
        console.log('Warning: socket is not defined');
      }
    });

@triitvn
Copy link

triitvn commented May 8, 2015

Thank you @Mad-Head so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants