Skip to content

Commit

Permalink
server: handle connection errors before handshake
Browse files Browse the repository at this point in the history
This commit fixes a critical issue that allowed to crash the server
with an unhandled error event sending an invalid packet that causes
parser error before a handshake.

Fixes: #76
PR-URL: #78
  • Loading branch information
aqrln authored and belochub committed Jan 22, 2018
1 parent 0328879 commit d044b8e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ Server.prototype._onRawConnection = function(socket) {
const connection = new Connection(
this.rawServer.createTransport(socket), this);

connection.on('error', (error) => {
this.emit('connectionError', error, connection);
});

connection.setTimeout(HANDSHAKE_TIMEOUT, () => {
if (!connection.handshakeDone) {
connection.close();
Expand All @@ -111,10 +115,6 @@ Server.prototype._onRawConnection = function(socket) {
Server.prototype._onClientConnect = function(connection) {
this.clients[connection.id] = connection;
this._cachedClientsArray.push(connection);

connection.on('error', (error) => {
this.emit('connectionError', error, connection);
});
};

// Client connection close event handler
Expand Down

0 comments on commit d044b8e

Please sign in to comment.