summaryrefslogtreecommitdiff
path: root/lib/http.js
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2013-02-28 16:58:24 +0100
committerBen Noordhuis <info@bnoordhuis.nl>2013-02-28 16:58:24 +0100
commitcb87920ba9c2871630ff37af6f0131fb1968dc95 (patch)
treed5e6e18f7b4cdfd184bb18be417b137ff3ad8538 /lib/http.js
parent0c1e7b53d0a33e112107f5387fbde9b2d688fb52 (diff)
parentd87904286024f5ceb6a2d0d5f17e919c775830a0 (diff)
downloadnode-cb87920ba9c2871630ff37af6f0131fb1968dc95.tar.gz
Merge remote-tracking branch 'origin/v0.8'
Conflicts: AUTHORS ChangeLog deps/uv/src/unix/pipe.c lib/http.js src/node_version.h
Diffstat (limited to 'lib/http.js')
-rw-r--r--lib/http.js28
1 files changed, 20 insertions, 8 deletions
diff --git a/lib/http.js b/lib/http.js
index e7299cc33..e5c709da0 100644
--- a/lib/http.js
+++ b/lib/http.js
@@ -437,6 +437,7 @@ function OutgoingMessage() {
this._trailer = '';
this.finished = false;
+ this._hangupClose = false;
}
util.inherits(OutgoingMessage, Stream);
@@ -491,14 +492,24 @@ OutgoingMessage.prototype._writeRaw = function(data, encoding) {
return this.connection.write(data, encoding);
} else if (this.connection && this.connection.destroyed) {
// The socket was destroyed. If we're still trying to write to it,
- // then something bad happened.
- // If we've already raised an error on this message, then just ignore.
- // XXX This was necessary in v0.8, but in v0.10, we no longer ignore
- // ECONNRESET anyway. Is this still required?
- if (!this._hadError) {
- this.emit('error', createHangUpError());
- this._hadError = true;
+ // then something bad happened, but it could be just that we haven't
+ // gotten the 'close' event yet.
+ //
+ // In v0.10 and later, this isn't a problem, since ECONNRESET isn't
+ // ignored in the first place. We'll probably emit 'close' on the
+ // next tick, but just in case it's not coming, set a timeout that
+ // will emit it for us.
+ if (!this._hangupClose) {
+ this._hangupClose = true;
+ var socket = this.socket;
+ var timer = setTimeout(function() {
+ socket.emit('close');
+ });
+ socket.on('close', function() {
+ clearTimeout(timer);
+ });
}
+ return false;
} else {
// buffer, as long as we're not destroyed.
this._buffer(data, encoding);
@@ -1810,7 +1821,8 @@ function connectionListener(socket) {
function serverSocketCloseListener() {
debug('server socket close');
// mark this parser as reusable
- freeParser(parser);
+ if (this.parser)
+ freeParser(this.parser);
abortIncoming();
}