Skip to content

Commit

Permalink
[fix] Do not throw when receiving an unhandled error packet (#3038)
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne authored Aug 26, 2017
1 parent 9d170a7 commit 1f0e64a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ Socket.prototype.onpacket = function(packet){
break;

case parser.ERROR:
this.emit('error', packet.data);
this.onerror(new Error(packet.data));
}
};

Expand Down
17 changes: 17 additions & 0 deletions test/socket.io.js
Original file line number Diff line number Diff line change
Expand Up @@ -1699,6 +1699,23 @@ describe('socket.io', function(){
});
});

it('should not crash when receiving an error packet without handler', function(done){
var srv = http();
var sio = io(srv);
srv.listen(function(){
var socket = client(srv, { reconnection: false });
sio.on('connection', function(s){
s.conn.on('upgrade', function(){
console.log('\033[96mNote: warning expected and normal in test.\033[39m');
socket.io.engine.write('44["handle me please"]');
setTimeout(function(){
done();
}, 100);
});
});
});
});

it('should not crash with raw binary', function(done){
var srv = http();
var sio = io(srv);
Expand Down

0 comments on commit 1f0e64a

Please sign in to comment.