Skip to content

Commit 1f0e64a

Browse files
authoredAug 26, 2017
[fix] Do not throw when receiving an unhandled error packet (#3038)
1 parent 9d170a7 commit 1f0e64a

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed
 

‎lib/socket.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ Socket.prototype.onpacket = function(packet){
340340
break;
341341

342342
case parser.ERROR:
343-
this.emit('error', packet.data);
343+
this.onerror(new Error(packet.data));
344344
}
345345
};
346346

‎test/socket.io.js

+17
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,23 @@ describe('socket.io', function(){
16991699
});
17001700
});
17011701

1702+
it('should not crash when receiving an error packet without handler', function(done){
1703+
var srv = http();
1704+
var sio = io(srv);
1705+
srv.listen(function(){
1706+
var socket = client(srv, { reconnection: false });
1707+
sio.on('connection', function(s){
1708+
s.conn.on('upgrade', function(){
1709+
console.log('\033[96mNote: warning expected and normal in test.\033[39m');
1710+
socket.io.engine.write('44["handle me please"]');
1711+
setTimeout(function(){
1712+
done();
1713+
}, 100);
1714+
});
1715+
});
1716+
});
1717+
});
1718+
17021719
it('should not crash with raw binary', function(done){
17031720
var srv = http();
17041721
var sio = io(srv);

0 commit comments

Comments
 (0)
Please sign in to comment.