@@ -534,8 +534,8 @@ function socketOnData(d) {
534
534
socket . removeListener ( 'end' , socketOnEnd ) ;
535
535
socket . removeListener ( 'drain' , ondrain ) ;
536
536
537
- if ( req . timeoutCb )
538
- socket . removeListener ( 'timeout' , req . timeoutCb ) ;
537
+ if ( req . timeoutCb ) socket . removeListener ( 'timeout' , req . timeoutCb ) ;
538
+ socket . removeListener ( 'timeout' , responseOnTimeout ) ;
539
539
540
540
parser . finish ( ) ;
541
541
freeParser ( parser , req , socket ) ;
@@ -645,6 +645,7 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
645
645
// Add our listener first, so that we guarantee socket cleanup
646
646
res . on ( 'end' , responseOnEnd ) ;
647
647
req . on ( 'prefinish' , requestOnPrefinish ) ;
648
+ socket . on ( 'timeout' , responseOnTimeout ) ;
648
649
649
650
// If the user did not listen for the 'response' event, then they
650
651
// can't possibly read the data, so we ._dump() it into the void
@@ -698,15 +699,16 @@ function responseKeepAlive(req) {
698
699
699
700
function responseOnEnd ( ) {
700
701
const req = this . req ;
702
+ const socket = req . socket ;
701
703
702
- if ( req . socket && req . timeoutCb ) {
703
- req . socket . removeListener ( 'timeout' , emitRequestTimeout ) ;
704
+ if ( socket ) {
705
+ if ( req . timeoutCb ) socket . removeListener ( 'timeout' , emitRequestTimeout ) ;
706
+ socket . removeListener ( 'timeout' , responseOnTimeout ) ;
704
707
}
705
708
706
709
req . _ended = true ;
707
710
708
711
if ( ! req . shouldKeepAlive ) {
709
- const socket = req . socket ;
710
712
if ( socket . writable ) {
711
713
debug ( 'AGENT socket.destroySoon()' ) ;
712
714
if ( typeof socket . destroySoon === 'function' )
@@ -725,6 +727,14 @@ function responseOnEnd() {
725
727
}
726
728
}
727
729
730
+ function responseOnTimeout ( ) {
731
+ const req = this . _httpMessage ;
732
+ if ( ! req ) return ;
733
+ const res = req . res ;
734
+ if ( ! res ) return ;
735
+ res . emit ( 'timeout' ) ;
736
+ }
737
+
728
738
function requestOnPrefinish ( ) {
729
739
const req = this ;
730
740
0 commit comments