diff --git a/lib/_http_server.js b/lib/_http_server.js index f1372b56dc6c1b..807e3df59d1985 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -581,11 +581,7 @@ function socketOnTimeout() { function socketOnClose(socket, state) { debug('server socket close'); - // Mark this parser as reusable - if (socket.parser) { - freeParser(socket.parser, null, socket); - } - + freeParser(socket.parser, null, socket); abortIncoming(state.incoming); } @@ -609,18 +605,15 @@ function socketOnEnd(server, socket, parser, state) { if (ret instanceof Error) { debug('parse error'); + // socketOnError has additional logic and will call socket.destroy(err). FunctionPrototypeCall(socketOnError, socket, ret); - return; - } - - if (!server.httpAllowHalfOpen) { - abortIncoming(state.incoming); - if (socket.writable) socket.end(); + } else if (!server.httpAllowHalfOpen) { + socket.end(); } else if (state.outgoing.length) { state.outgoing[state.outgoing.length - 1]._last = true; } else if (socket._httpMessage) { socket._httpMessage._last = true; - } else if (socket.writable) { + } else { socket.end(); } } @@ -635,6 +628,7 @@ function socketOnData(server, socket, parser, state, d) { function onRequestTimeout(socket) { socket[kRequestTimeout] = undefined; + // socketOnError has additional logic and will call socket.destroy(err). ReflectApply(socketOnError, socket, [new ERR_HTTP_REQUEST_TIMEOUT()]); }