File tree 2 files changed +12
-0
lines changed
2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,7 @@ function listOnTimeout() {
85
85
if ( domain )
86
86
domain . enter ( ) ;
87
87
threw = true ;
88
+ first . _called = true ;
88
89
first . _onTimeout ( ) ;
89
90
if ( domain )
90
91
domain . exit ( ) ;
@@ -305,6 +306,9 @@ Timeout.prototype.unref = function() {
305
306
if ( this . _handle ) {
306
307
this . _handle . unref ( ) ;
307
308
} else if ( typeof ( this . _onTimeout ) === 'function' ) {
309
+ // Prevent running callback multiple times
310
+ // when unref() is called during the callback
311
+ if ( this . _called ) return ;
308
312
var now = Timer . now ( ) ;
309
313
if ( ! this . _idleStart ) this . _idleStart = now ;
310
314
var delay = this . _idleStart + this . _idleTimeout - now ;
@@ -492,6 +496,7 @@ function unrefTimeout() {
492
496
if ( domain ) domain . enter ( ) ;
493
497
threw = true ;
494
498
debug ( 'unreftimer firing timeout' ) ;
499
+ first . _called = true ;
495
500
first . _onTimeout ( ) ;
496
501
threw = false ;
497
502
if ( domain )
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ var interval_fired = false,
5
5
timeout_fired = false ,
6
6
unref_interval = false ,
7
7
unref_timer = false ,
8
+ unref_callbacks = 0 ,
8
9
interval , check_unref , checks = 0 ;
9
10
10
11
var LONG_TIME = 10 * 1000 ;
@@ -34,6 +35,11 @@ check_unref = setInterval(function() {
34
35
checks += 1 ;
35
36
} , 100 ) ;
36
37
38
+ setTimeout ( function ( ) {
39
+ unref_callbacks ++ ;
40
+ this . unref ( ) ;
41
+ } , SHORT_TIME ) ;
42
+
37
43
// Should not assert on args.Holder()->InternalFieldCount() > 0. See #4261.
38
44
( function ( ) {
39
45
var t = setInterval ( function ( ) { } , 1 ) ;
@@ -46,4 +52,5 @@ process.on('exit', function() {
46
52
assert . strictEqual ( timeout_fired , false , 'Timeout should not fire' ) ;
47
53
assert . strictEqual ( unref_timer , true , 'An unrefd timeout should still fire' ) ;
48
54
assert . strictEqual ( unref_interval , true , 'An unrefd interval should still fire' ) ;
55
+ assert . strictEqual ( unref_callbacks , 1 , 'Callback should only run once' ) ;
49
56
} ) ;
You can’t perform that action at this time.
0 commit comments