diff --git a/lib/protocol/Connection.js b/lib/protocol/Connection.js index 663b851..5b2deb4 100644 --- a/lib/protocol/Connection.js +++ b/lib/protocol/Connection.js @@ -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); diff --git a/lib/protocol/ConnectionManager.js b/lib/protocol/ConnectionManager.js index e025eed..93136f3 100644 --- a/lib/protocol/ConnectionManager.js +++ b/lib/protocol/ConnectionManager.js @@ -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); @@ -99,7 +94,6 @@ ConnectionManager.prototype._openConnectionMultiDbCase = function _openConnectio } if (info.isConnected) { - conn.removeListener('error', onError); cb(null); } else { conn._closeSilently(); diff --git a/test/hdb.Client.js b/test/hdb.Client.js index 63b38cf..41b1fbd 100644 --- a/test/hdb.Client.js +++ b/test/hdb.Client.js @@ -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(); }); });