Fix unhandled error during client connection
Client actions utilizing an EventEmitter may generate unhandled errors, especially during initial connection. Tracking whether the emitter has been sent via callback is critical for proper routing of such errors. Fix mcavage/node-ldapjs#144
This commit is contained in:
parent
df13275b8e
commit
ebcba1205d
|
@ -757,14 +757,20 @@ Client.prototype._send = function _send(message, expect, emitter, callback) {
|
|||
var log = this.log;
|
||||
var self = this;
|
||||
var timer = false;
|
||||
var sentEmitter = false;
|
||||
|
||||
if (!conn)
|
||||
return callback(new ConnectionError('no socket'));
|
||||
|
||||
function _done(event, obj) {
|
||||
if (emitter) {
|
||||
if (event === 'error')
|
||||
if (event === 'error') {
|
||||
// Error will go unhandled if emitter hasn't been sent via callback.
|
||||
// Execute callback with the error instead.
|
||||
if (!sentEmitter)
|
||||
return callback(obj);
|
||||
emitter.removeAllListeners('end');
|
||||
}
|
||||
if (event === 'end')
|
||||
emitter.removeAllListeners('error');
|
||||
|
||||
|
@ -878,6 +884,7 @@ Client.prototype._send = function _send(message, expect, emitter, callback) {
|
|||
conn.unbindMessageID = message.id;
|
||||
conn.end();
|
||||
} else if (emitter) {
|
||||
sentEmitter = true;
|
||||
return callback(null, emitter);
|
||||
}
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue