-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
timers: assure setTimeout callback only runs once #1231
Changes from 1 commit
951168f
bc94f6c
a58d149
c99318c
1a824b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,7 @@ function listOnTimeout() { | |
if (domain) | ||
domain.enter(); | ||
threw = true; | ||
first._called = true; | ||
first._onTimeout(); | ||
if (domain) | ||
domain.exit(); | ||
|
@@ -305,6 +306,9 @@ Timeout.prototype.unref = function() { | |
if (this._handle) { | ||
this._handle.unref(); | ||
} else if (typeof(this._onTimeout) === 'function') { | ||
// Prevent running callback multiple times | ||
// when unref() is called during the callback | ||
if (this._called) return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's probably best to just do this before There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I was unsure here too, but since I only wanted to prevent the |
||
var now = Timer.now(); | ||
if (!this._idleStart) this._idleStart = now; | ||
var delay = this._idleStart + this._idleTimeout - now; | ||
|
@@ -492,6 +496,7 @@ function unrefTimeout() { | |
if (domain) domain.enter(); | ||
threw = true; | ||
debug('unreftimer firing timeout'); | ||
first._called = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strictly, this one wasn't neccessary to fix the issue, but I thought it's better to track all callback calls if there are more edge cases. |
||
first._onTimeout(); | ||
threw = false; | ||
if (domain) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add
this._called = false
to the constructor.