Skip to content

Commit

Permalink
Emit errors only when listeners are present
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpenev-s committed Nov 23, 2016
1 parent 68b275e commit 95f39bc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
4 changes: 3 additions & 1 deletion lib/protocol/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,10 @@ Connection.prototype._addListeners = function _addListeners(socket) {
if (cb) {
self._state.receive = null; // a callback should be called only once
cb(err);
} else {
} else if (self.listenerCount('error')) {
self.emit('error', err);
} else {
debug('onerror', err);
}
}
socket.on('error', onerror);
Expand Down
6 changes: 0 additions & 6 deletions lib/protocol/ConnectionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ ConnectionManager.prototype._openConnectionMultiDbCase = function _openConnectio
}
}

function onError(err) {
cb(err);
}
conn.on('error', onError);

function handleError(err) {
conn.close();
cb(err);
Expand All @@ -99,7 +94,6 @@ ConnectionManager.prototype._openConnectionMultiDbCase = function _openConnectio
}

if (info.isConnected) {
conn.removeListener('error', onError);
cb(null);
} else {
conn._closeSilently();
Expand Down
8 changes: 4 additions & 4 deletions test/hdb.Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,12 +513,12 @@ describe('hdb', function () {
databaseName: 'DB0'
});

client._connection.fetchDbConnectInfo = function () {
client._connection.emit('error', new Error('Network error emitted'));
client._connection.fetchDbConnectInfo = function (options, cb) {
cb(new Error('Network error'));
};

client.connect(function (err) {
err.message.should.equal('Could not connect to any host: [ localhost:30013 - Network error emitted ]');
err.message.should.equal('Could not connect to any host: [ localhost:30013 - Network error ]');
done();
});
});
Expand Down Expand Up @@ -695,6 +695,6 @@ describe('hdb', function () {
});

});

});
});

0 comments on commit 95f39bc

Please sign in to comment.