diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index c004b37158..38a07b290a 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -117,7 +117,7 @@ function WritableState(options, stream) { this.prefinished = false; // Internal, used in net.js and _tls_wrap.js - this._errorEmitted = false; + this.errorEmitted = false; } function Writable(options) { @@ -274,8 +274,8 @@ function onwriteError(stream, state, sync, er, cb) { cb(er); } + stream._writableState.errorEmitted = true; stream.emit('error', er); - stream._errorEmitted = true; } function onwriteStateUpdate(state) { diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index ff762107d2..3cda50d2d5 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -238,9 +238,9 @@ TLSSocket.prototype._init = function(socket) { } this.ssl.onerror = function(err) { - if (self._errorEmitted) + if (self._writableState.errorEmitted) return; - self._errorEmitted = true; + self._writableState.errorEmitted = true; // Destroy socket if error happened before handshake's finish if (!this._secureEstablished) { diff --git a/lib/net.js b/lib/net.js index 3d0fe6941e..0bcacec0af 100644 --- a/lib/net.js +++ b/lib/net.js @@ -428,11 +428,11 @@ Socket.prototype._destroy = function(exception, cb) { function fireErrorCallbacks() { if (cb) cb(exception); - if (exception && !self._errorEmitted) { + if (exception && !self._writableState.errorEmitted) { process.nextTick(function() { self.emit('error', exception); }); - self._errorEmitted = true; + self._writableState.errorEmitted = true; } };