From 93afe4e01c73eb4e36096e5d493fd681af0d0747 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Fri, 25 Aug 2017 21:44:36 +0200 Subject: [PATCH] do not throw when receiving an unhandled error packet --- lib/socket.js | 2 +- test/socket.io.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/socket.js b/lib/socket.js index a907bf3381..91ddbbdf03 100644 --- a/lib/socket.js +++ b/lib/socket.js @@ -340,7 +340,7 @@ Socket.prototype.onpacket = function(packet){ break; case parser.ERROR: - this.emit('error', packet.data); + this.onerror(new Error(packet.data)); } }; diff --git a/test/socket.io.js b/test/socket.io.js index bd2e65d2ad..44d8d1a8f7 100644 --- a/test/socket.io.js +++ b/test/socket.io.js @@ -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);