| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ae2eff2 commit 553d95d
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -274,12 +274,12 @@ exports.setInterval = function(callback, repeat) { | |||
| 274 | 274 | function wrapper() { | |
| 275 | 275 | timer._repeat(); | |
| 276 | 276 | ||
| 277 | - // Timer might be closed - no point in restarting it | ||
| 278 | - if (!timer._repeat) | ||
| 277 | + // Do not re-arm unenroll'd or closed timers. | ||
| 278 | + if (timer._idleTimeout === -1) | ||
| 279 | 279 | return; | |
| 280 | 280 | ||
| 281 | 281 | // If timer is unref'd (or was - it's permanently removed from the list.) | |
| 282 | - if (this._handle) { | ||
| 282 | + if (this._handle && timer instanceof Timeout) { | ||
| 283 | 283 | this._handle.start(repeat, 0); | |
| 284 | 284 | } else { | |
| 285 | 285 | timer._idleTimeout = repeat; | |
@@ -309,9 +309,17 @@ const Timeout = function(after) { | |||
| 309 | 309 | ||
| 310 | 310 | ||
| 311 | 311 | function unrefdHandle() { | |
| 312 | - this.owner._onTimeout(); | ||
| 313 | - if (!this.owner._repeat) | ||
| 312 | + // Don't attempt to call the callback if it is not a function. | ||
| 313 | + if (typeof this.owner._onTimeout === 'function') { | ||
| 314 | + this.owner._onTimeout(); | ||
| 315 | + } | ||
| 316 | + | ||
| 317 | + // Make sure we clean up if the callback is no longer a function | ||
| 318 | + // even if the timer is an interval. | ||
| 319 | + if (!this.owner._repeat | ||
| 320 | + || typeof this.owner._onTimeout !== 'function') { | ||
| 314 | 321 | this.owner.close(); | |
| 322 | + } | ||
| 315 | 323 | } | |
| 316 | 324 | ||
| 317 | 325 | ||
@@ -351,6 +359,7 @@ Timeout.prototype.ref = function() { | |||
| 351 | 359 | Timeout.prototype.close = function() { | |
| 352 | 360 | this._onTimeout = null; | |
| 353 | 361 | if (this._handle) { | |
| 362 | + this._idleTimeout = -1; | ||
| 354 | 363 | this._handle[kOnTimeout] = null; | |
| 355 | 364 | this._handle.close(); | |
| 356 | 365 | } else { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,49 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const timers = require('timers'); | ||
| 5 | + | ||
| 6 | + { | ||
| 7 | + const interval = setInterval(common.mustCall(() => { | ||
| 8 | + clearTimeout(interval); | ||
| 9 | + }), 1).unref(); | ||
| 10 | + } | ||
| 11 | + | ||
| 12 | + { | ||
| 13 | + const interval = setInterval(common.mustCall(() => { | ||
| 14 | + interval.close(); | ||
| 15 | + }), 1).unref(); | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + { | ||
| 19 | + const interval = setInterval(common.mustCall(() => { | ||
| 20 | + timers.unenroll(interval); | ||
| 21 | + }), 1).unref(); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + { | ||
| 25 | + const interval = setInterval(common.mustCall(() => { | ||
| 26 | + interval._idleTimeout = -1; | ||
| 27 | + }), 1).unref(); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + { | ||
| 31 | + const interval = setInterval(common.mustCall(() => { | ||
| 32 | + interval._onTimeout = null; | ||
| 33 | + }), 1).unref(); | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + // Use timers' intrinsic behavior to keep this open | ||
| 37 | + // exactly long enough for the problem to manifest. | ||
| 38 | + // | ||
| 39 | + // See https://github.com/nodejs/node/issues/9561 | ||
| 40 | + // | ||
| 41 | + // Since this is added after it will always fire later | ||
| 42 | + // than the previous timeouts, unrefed or not. | ||
| 43 | + // | ||
| 44 | + // Keep the event loop alive for one timeout and then | ||
| 45 | + // another. Any problems will occur when the second | ||
| 46 | + // should be called but before it is able to be. | ||
| 47 | + setTimeout(common.mustCall(() => { | ||
| 48 | + setTimeout(common.mustCall(() => {}), 1); | ||
| 49 | + }), 1); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments