Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Guard against emitting 'end' twice on http responses
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed May 15, 2012
1 parent ea4b1c1 commit 14a5b45
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/http.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 14a5b45

Please sign in to comment.