@@ -525,8 +525,8 @@ function socketOnData(d) {
525
525
socket . removeListener ( 'end' , socketOnEnd ) ;
526
526
socket . removeListener ( 'drain' , ondrain ) ;
527
527
528
- if ( req . timeoutCb )
529
- socket . removeListener ( 'timeout' , req . timeoutCb ) ;
528
+ if ( req . timeoutCb ) socket . removeListener ( 'timeout' , req . timeoutCb ) ;
529
+ socket . removeListener ( 'timeout' , responseOnTimeout ) ;
530
530
531
531
parser . finish ( ) ;
532
532
freeParser ( parser , req , socket ) ;
@@ -634,6 +634,7 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
634
634
// Add our listener first, so that we guarantee socket cleanup
635
635
res . on ( 'end' , responseOnEnd ) ;
636
636
req . on ( 'prefinish' , requestOnPrefinish ) ;
637
+ socket . on ( 'timeout' , responseOnTimeout ) ;
637
638
638
639
// If the user did not listen for the 'response' event, then they
639
640
// can't possibly read the data, so we ._dump() it into the void
@@ -687,15 +688,16 @@ function responseKeepAlive(req) {
687
688
688
689
function responseOnEnd ( ) {
689
690
const req = this . req ;
691
+ const socket = req . socket ;
690
692
691
- if ( req . socket && req . timeoutCb ) {
692
- req . socket . removeListener ( 'timeout' , emitRequestTimeout ) ;
693
+ if ( socket ) {
694
+ if ( req . timeoutCb ) socket . removeListener ( 'timeout' , emitRequestTimeout ) ;
695
+ socket . removeListener ( 'timeout' , responseOnTimeout ) ;
693
696
}
694
697
695
698
req . _ended = true ;
696
699
697
700
if ( ! req . shouldKeepAlive ) {
698
- const socket = req . socket ;
699
701
if ( socket . writable ) {
700
702
debug ( 'AGENT socket.destroySoon()' ) ;
701
703
if ( typeof socket . destroySoon === 'function' )
@@ -714,6 +716,14 @@ function responseOnEnd() {
714
716
}
715
717
}
716
718
719
+ function responseOnTimeout ( ) {
720
+ const req = this . _httpMessage ;
721
+ if ( ! req ) return ;
722
+ const res = req . res ;
723
+ if ( ! res ) return ;
724
+ res . emit ( 'timeout' ) ;
725
+ }
726
+
717
727
function requestOnPrefinish ( ) {
718
728
const req = this ;
719
729
0 commit comments