fix(socket): Fixes socket.use error packet which drops nodejs due to … #2772

merged 4 commits into from Dec 1, 2016


None yet

2 participants

serhiisol commented Nov 30, 2016 edited

This PR fixes #2771

The kind of change this PR does introduce

  • a bug fix

Current behaviour

Socket.use middleware drops nodejs process if error thrown in next function

New behaviour

Socket.use middleware sends error packet correctly without dropping nodejs instance.

Other information (e.g. related issues)

Socket cannot emit error event, because default behavior of EventEmitter will drop nodejs instance.


Hi! Thanks for the PR. Actually, there seems to be an issue in the tests:

it('should pass errors', function(done){
  var srv = http();
  var sio = io(srv);

    var socket = client(srv, { multiplex: false });

    socket.emit('join', 'woot');

    // + socket.on('error', function(err){
    // +   expect(err)'Authentication error');
    // +  done();
    // + });

    sio.on('connection', function(socket){
      socket.use(function(event, next){
        next(new Error('Authentication error'));
      socket.use(function(event, next){
        done(new Error('nope'));

      socket.on('join', function(){
        done(new Error('nope'));
      // - socket.on('error', function(err){
      // -   expect(err)'Authentication error');
      // -   done();
      // - });

According to the docs:

Errors passed to middleware callbacks are sent as special error packets to clients.

Your first commit should be sufficient I think. Could you please update the tests, by renaming the 2nd socket?

serhiisol commented Nov 30, 2016 edited

Hi @darrachequesne, I noticed that after deep debugging, and I've updated PR with fixes. In the test clientSocket should listen to error event, but not server side one

@darrachequesne darrachequesne merged commit 1e31769 into socketio:master Dec 1, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
@serhiisol serhiisol deleted the unknown repository branch Dec 1, 2016
@darrachequesne darrachequesne added this to the 1.8.2 milestone Dec 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment