diff options
Diffstat (limited to 'lib/_http_server.js')
-rw-r--r-- | lib/_http_server.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/_http_server.js b/lib/_http_server.js index 862b7c970b..6dc29c855e 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -611,6 +611,19 @@ function onParserExecuteCommon(server, socket, parser, state, ret, d) { } } +function clearIncoming(req) { + req = req || this; + const parser = req.socket && req.socket.parser; + // Reset the .incoming property so that the request object can be gc'ed. + if (parser && parser.incoming === req) { + if (req.readableEnded) { + parser.incoming = null; + } else { + req.on('end', clearIncoming); + } + } +} + function resOnFinish(req, res, socket, state, server) { // Usually the first incoming element should be our request. it may // be that in the case abortIncoming() was called that the incoming @@ -618,6 +631,7 @@ function resOnFinish(req, res, socket, state, server) { assert(state.incoming.length === 0 || state.incoming[0] === req); state.incoming.shift(); + clearIncoming(req); // If the user never called req.read(), and didn't pipe() or // .resume() or .on('data'), then we call req._dump() so that the |