parent
5c832e44c3
commit
dee5270a6c
@ -104,6 +104,9 @@ function WritableState(options, stream) {
|
|||||||
this.writelen = 0;
|
this.writelen = 0;
|
||||||
|
|
||||||
this.buffer = [];
|
this.buffer = [];
|
||||||
|
|
||||||
|
// True if the error was already emitted and should not be thrown again
|
||||||
|
this.errorEmitted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Writable(options) {
|
function Writable(options) {
|
||||||
@ -232,6 +235,7 @@ function onwriteError(stream, state, sync, er, cb) {
|
|||||||
else
|
else
|
||||||
cb(er);
|
cb(er);
|
||||||
|
|
||||||
|
stream._writableState.errorEmitted = true;
|
||||||
stream.emit('error', er);
|
stream.emit('error', er);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +122,6 @@ exports._normalizeConnectArgs = normalizeConnectArgs;
|
|||||||
// called when creating new Socket, or when re-using a closed Socket
|
// called when creating new Socket, or when re-using a closed Socket
|
||||||
function initSocketHandle(self) {
|
function initSocketHandle(self) {
|
||||||
self.destroyed = false;
|
self.destroyed = false;
|
||||||
self.errorEmitted = false;
|
|
||||||
self.bytesRead = 0;
|
self.bytesRead = 0;
|
||||||
self._bytesDispatched = 0;
|
self._bytesDispatched = 0;
|
||||||
|
|
||||||
@ -436,11 +435,11 @@ Socket.prototype._destroy = function(exception, cb) {
|
|||||||
|
|
||||||
function fireErrorCallbacks() {
|
function fireErrorCallbacks() {
|
||||||
if (cb) cb(exception);
|
if (cb) cb(exception);
|
||||||
if (exception && !self.errorEmitted) {
|
if (exception && !self._writableState.errorEmitted) {
|
||||||
process.nextTick(function() {
|
process.nextTick(function() {
|
||||||
self.emit('error', exception);
|
self.emit('error', exception);
|
||||||
});
|
});
|
||||||
self.errorEmitted = true;
|
self._writableState.errorEmitted = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
50
test/simple/test-net-error-twice.js
Normal file
50
test/simple/test-net-error-twice.js
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
// Copyright Joyent, Inc. and other Node contributors.
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
// copy of this software and associated documentation files (the
|
||||||
|
// "Software"), to deal in the Software without restriction, including
|
||||||
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||||
|
// persons to whom the Software is furnished to do so, subject to the
|
||||||
|
// following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included
|
||||||
|
// in all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||||
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||||
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||||
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||||
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
var common = require('../common');
|
||||||
|
var assert = require('assert');
|
||||||
|
var net = require('net');
|
||||||
|
|
||||||
|
var buf = new Buffer(2 * 1024 * 1024);
|
||||||
|
|
||||||
|
buf.fill(0x62);
|
||||||
|
|
||||||
|
var errs = [];
|
||||||
|
|
||||||
|
var srv = net.createServer(function onConnection(conn) {
|
||||||
|
conn.write(buf);
|
||||||
|
conn.on('error', function (err) {
|
||||||
|
errs.push(err);
|
||||||
|
if (errs.length > 1 && errs[0] === errs[1])
|
||||||
|
assert(false, "We should not be emitting the same error twice");
|
||||||
|
});
|
||||||
|
}).listen(common.PORT, function () {
|
||||||
|
var client = net.connect({ port: common.PORT });
|
||||||
|
|
||||||
|
client.on('connect', function () {
|
||||||
|
client.resume();
|
||||||
|
client.destroy();
|
||||||
|
});
|
||||||
|
}).unref();
|
||||||
|
|
||||||
|
process.on('exit', function() {
|
||||||
|
assert.equal(errs.length, 1);
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user