-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
Fix timer .unref()
handle management once and for all
#1330
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
340be32
timers: fix unref() memory leak
trevnorris 31d8801
timers: don't close interval timers when unrefd
0b39408
timers: do not restart the interval after close
indutny ca615ac
test: add test for a unref'ed timer leak
indutny 452571b
timers: remove redundant code
indutny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
var assert = require('assert'); | ||
|
||
var called = 0; | ||
var closed = 0; | ||
|
||
var timeout = setTimeout(function() { | ||
called++; | ||
}, 10); | ||
timeout.unref(); | ||
|
||
// Wrap `close` method to check if the handle was closed | ||
var close = timeout._handle.close; | ||
timeout._handle.close = function() { | ||
closed++; | ||
return close.apply(this, arguments); | ||
}; | ||
|
||
// Just to keep process alive and let previous timer's handle die | ||
setTimeout(function() { | ||
}, 50); | ||
|
||
process.on('exit', function() { | ||
assert.equal(called, 1); | ||
assert.equal(closed, 1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* This test is a regression test for joyent/node#8900. | ||
*/ | ||
var assert = require('assert'); | ||
|
||
var N = 5; | ||
var nbIntervalFired = 0; | ||
var timer = setInterval(function() { | ||
++nbIntervalFired; | ||
if (nbIntervalFired === N) | ||
clearInterval(timer); | ||
}, 1); | ||
|
||
timer.unref(); | ||
|
||
setTimeout(function onTimeout() { | ||
assert.strictEqual(nbIntervalFired, N); | ||
}, 100); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This will run
this._handle.close()
which runsuv_close(wrap->handle__, OnClose)
. Are we sure that the list of timers attached to thisTimerWrap
instance is empty before this runs?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.
No list attached here for sure.
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.
great. then LGTM.