@@ -581,11 +581,7 @@ function socketOnTimeout() {
581
581
582
582
function socketOnClose ( socket , state ) {
583
583
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 ) ;
589
585
abortIncoming ( state . incoming ) ;
590
586
}
591
587
@@ -602,18 +598,15 @@ function socketOnEnd(server, socket, parser, state) {
602
598
603
599
if ( ret instanceof Error ) {
604
600
debug ( 'parse error' ) ;
601
+ // socketOnError has additional logic and will call socket.destroy(err).
605
602
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 ( ) ;
612
605
} else if ( state . outgoing . length ) {
613
606
state . outgoing [ state . outgoing . length - 1 ] . _last = true ;
614
607
} else if ( socket . _httpMessage ) {
615
608
socket . _httpMessage . _last = true ;
616
- } else if ( socket . writable ) {
609
+ } else {
617
610
socket . end ( ) ;
618
611
}
619
612
}
@@ -628,6 +621,7 @@ function socketOnData(server, socket, parser, state, d) {
628
621
629
622
function onRequestTimeout ( socket ) {
630
623
socket [ kRequestTimeout ] = undefined ;
624
+ // socketOnError has additional logic and will call socket.destroy(err).
631
625
ReflectApply ( socketOnError , socket , [ new ERR_HTTP_REQUEST_TIMEOUT ( ) ] ) ;
632
626
}
633
627
0 commit comments