@@ -140,6 +140,7 @@ function Socket(options) {
140
140
this . _connecting = false ;
141
141
this . _hadError = false ;
142
142
this . _handle = null ;
143
+ this . _parent = null ;
143
144
this . _host = null ;
144
145
145
146
if ( util . isNumber ( options ) )
@@ -199,6 +200,13 @@ function Socket(options) {
199
200
}
200
201
util . inherits ( Socket , stream . Duplex ) ;
201
202
203
+
204
+ Socket . prototype . _unrefTimer = function unrefTimer ( ) {
205
+ for ( var s = this ; s !== null ; s = s . _parent )
206
+ timers . _unrefActive ( s ) ;
207
+ } ;
208
+
209
+
202
210
// the user has called .end(), and all the bytes have been
203
211
// sent out to the other side.
204
212
// If allowHalfOpen is false, or if the readable side has
@@ -464,7 +472,8 @@ Socket.prototype._destroy = function(exception, cb) {
464
472
465
473
this . readable = this . writable = false ;
466
474
467
- timers . unenroll ( this ) ;
475
+ for ( var s = this ; s !== null ; s = s . _parent )
476
+ timers . unenroll ( s ) ;
468
477
469
478
debug ( 'close' ) ;
470
479
if ( this . _handle ) {
@@ -509,7 +518,7 @@ function onread(nread, buffer) {
509
518
var self = handle . owner ;
510
519
assert ( handle === self . _handle , 'handle != self._handle' ) ;
511
520
512
- timers . _unrefActive ( self ) ;
521
+ self . _unrefTimer ( ) ;
513
522
514
523
debug ( 'onread' , nread ) ;
515
524
@@ -641,7 +650,7 @@ Socket.prototype._writeGeneric = function(writev, data, encoding, cb) {
641
650
this . _pendingData = null ;
642
651
this . _pendingEncoding = '' ;
643
652
644
- timers . _unrefActive ( this ) ;
653
+ this . _unrefTimer ( ) ;
645
654
646
655
if ( ! this . _handle ) {
647
656
this . _destroy ( new Error ( 'This socket is closed.' ) , cb ) ;
@@ -769,7 +778,7 @@ function afterWrite(status, handle, req, err) {
769
778
return ;
770
779
}
771
780
772
- timers . _unrefActive ( self ) ;
781
+ self . _unrefTimer ( ) ;
773
782
774
783
if ( self !== process . stderr && self !== process . stdout )
775
784
debug ( 'afterWrite call cb' ) ;
@@ -872,7 +881,7 @@ Socket.prototype.connect = function(options, cb) {
872
881
self . once ( 'connect' , cb ) ;
873
882
}
874
883
875
- timers . _unrefActive ( this ) ;
884
+ this . _unrefTimer ( ) ;
876
885
877
886
self . _connecting = true ;
878
887
self . writable = true ;
@@ -924,7 +933,7 @@ Socket.prototype.connect = function(options, cb) {
924
933
self . _destroy ( ) ;
925
934
} ) ;
926
935
} else {
927
- timers . _unrefActive ( self ) ;
936
+ self . _unrefTimer ( ) ;
928
937
connect ( self ,
929
938
ip ,
930
939
port ,
@@ -969,7 +978,7 @@ function afterConnect(status, handle, req, readable, writable) {
969
978
if ( status == 0 ) {
970
979
self . readable = readable ;
971
980
self . writable = writable ;
972
- timers . _unrefActive ( self ) ;
981
+ self . _unrefTimer ( ) ;
973
982
974
983
self . emit ( 'connect' ) ;
975
984
0 commit comments