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);