@@ -120,6 +120,7 @@ function Socket(options) {
120
120
this . _connecting = false ;
121
121
this . _hadError = false ;
122
122
this . _handle = null ;
123
+ this . _parent = null ;
123
124
this . _host = null ;
124
125
125
126
if ( typeof options === 'number' )
@@ -179,6 +180,11 @@ function Socket(options) {
179
180
}
180
181
util . inherits ( Socket , stream . Duplex ) ;
181
182
183
+ Socket . prototype . _unrefTimer = function unrefTimer ( ) {
184
+ for ( var s = this ; s !== null ; s = s . _parent )
185
+ timers . _unrefActive ( s ) ;
186
+ } ;
187
+
182
188
// the user has called .end(), and all the bytes have been
183
189
// sent out to the other side.
184
190
// If allowHalfOpen is false, or if the readable side has
@@ -445,7 +451,8 @@ Socket.prototype._destroy = function(exception, cb) {
445
451
446
452
this . readable = this . writable = false ;
447
453
448
- timers . unenroll ( this ) ;
454
+ for ( var s = this ; s !== null ; s = s . _parent )
455
+ timers . unenroll ( s ) ;
449
456
450
457
debug ( 'close' ) ;
451
458
if ( this . _handle ) {
@@ -490,7 +497,7 @@ function onread(nread, buffer) {
490
497
var self = handle . owner ;
491
498
assert ( handle === self . _handle , 'handle != self._handle' ) ;
492
499
493
- timers . _unrefActive ( self ) ;
500
+ self . _unrefTimer ( ) ;
494
501
495
502
debug ( 'onread' , nread ) ;
496
503
@@ -621,7 +628,7 @@ Socket.prototype._writeGeneric = function(writev, data, encoding, cb) {
621
628
this . _pendingData = null ;
622
629
this . _pendingEncoding = '' ;
623
630
624
- timers . _unrefActive ( this ) ;
631
+ this . _unrefTimer ( ) ;
625
632
626
633
if ( ! this . _handle ) {
627
634
this . _destroy ( new Error ( 'This socket is closed.' ) , cb ) ;
@@ -749,7 +756,7 @@ function afterWrite(status, handle, req, err) {
749
756
return ;
750
757
}
751
758
752
- timers . _unrefActive ( self ) ;
759
+ self . _unrefTimer ( ) ;
753
760
754
761
if ( self !== process . stderr && self !== process . stdout )
755
762
debug ( 'afterWrite call cb' ) ;
@@ -864,7 +871,7 @@ Socket.prototype.connect = function(options, cb) {
864
871
self . once ( 'connect' , cb ) ;
865
872
}
866
873
867
- timers . _unrefActive ( this ) ;
874
+ this . _unrefTimer ( ) ;
868
875
869
876
self . _connecting = true ;
870
877
self . writable = true ;
@@ -919,7 +926,7 @@ Socket.prototype.connect = function(options, cb) {
919
926
self . _destroy ( ) ;
920
927
} ) ;
921
928
} else {
922
- timers . _unrefActive ( self ) ;
929
+ self . _unrefTimer ( ) ;
923
930
connect ( self ,
924
931
ip ,
925
932
port ,
@@ -964,7 +971,7 @@ function afterConnect(status, handle, req, readable, writable) {
964
971
if ( status == 0 ) {
965
972
self . readable = readable ;
966
973
self . writable = writable ;
967
- timers . _unrefActive ( self ) ;
974
+ self . _unrefTimer ( ) ;
968
975
969
976
self . emit ( 'connect' ) ;
970
977
0 commit comments