From 14a5b45c06c327c838d93130cdfeec03e8fad1fb Mon Sep 17 00:00:00 2001 From: isaacs Date: Mon, 14 May 2012 17:21:20 -0700 Subject: [PATCH] Guard against emitting 'end' twice on http responses --- lib/http.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/http.js b/lib/http.js index 61204cad4b..83d0c556ce 100644 --- a/lib/http.js +++ b/lib/http.js @@ -125,7 +125,10 @@ function parserOnMessageComplete() { if (!parser.incoming.upgrade) { // For upgraded connections, also emit this after parser.execute parser.incoming.readable = false; - parser.incoming.emit('end'); + if (!parser.incoming._ended) { + parser.incoming._ended = true; + parser.incoming.emit('end'); + } } if (parser.socket.readable) { @@ -1158,7 +1161,10 @@ function socketCloseListener() { if (req.res && req.res.readable) { // Socket closed before we emitted "end" below. req.res.emit('aborted'); - req.res.emit('end'); + if (!req.res._ended) { + req.res._ended = true; + req.res.emit('end'); + } req.res.emit('close'); } else if (!req.res && !req._hadError) { // This socket error fired before we started to