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