@@ -581,11 +581,7 @@ function socketOnTimeout() {
581581
582582function socketOnClose ( socket , state ) {
583583 debug ( 'server socket close' ) ;
584- // Mark this parser as reusable
585- if ( socket . parser ) {
586- freeParser ( socket . parser , null , socket ) ;
587- }
588-
584+ freeParser ( socket . parser , null , socket ) ;
589585 abortIncoming ( state . incoming ) ;
590586}
591587
@@ -602,18 +598,15 @@ function socketOnEnd(server, socket, parser, state) {
602598
603599 if ( ret instanceof Error ) {
604600 debug ( 'parse error' ) ;
601+ // socketOnError has additional logic and will call socket.destroy(err).
605602 FunctionPrototypeCall ( socketOnError , socket , ret ) ;
606- return ;
607- }
608-
609- if ( ! server . httpAllowHalfOpen ) {
610- abortIncoming ( state . incoming ) ;
611- if ( socket . writable ) socket . end ( ) ;
603+ } else if ( ! server . httpAllowHalfOpen ) {
604+ socket . end ( ) ;
612605 } else if ( state . outgoing . length ) {
613606 state . outgoing [ state . outgoing . length - 1 ] . _last = true ;
614607 } else if ( socket . _httpMessage ) {
615608 socket . _httpMessage . _last = true ;
616- } else if ( socket . writable ) {
609+ } else {
617610 socket . end ( ) ;
618611 }
619612}
@@ -628,6 +621,7 @@ function socketOnData(server, socket, parser, state, d) {
628621
629622function onRequestTimeout ( socket ) {
630623 socket [ kRequestTimeout ] = undefined ;
624+ // socketOnError has additional logic and will call socket.destroy(err).
631625 ReflectApply ( socketOnError , socket , [ new ERR_HTTP_REQUEST_TIMEOUT ( ) ] ) ;
632626}
633627
0 commit comments