-
Notifications
You must be signed in to change notification settings - Fork 30k
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
node,timers: fix beforeExit with unrefed timers #2795
Changes from 2 commits
737d9b6
01df246
85854e0
baaaabf
c358723
5d7262c
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 |
---|---|---|
|
@@ -1543,6 +1543,18 @@ void GetActiveHandles(const FunctionCallbackInfo<Value>& args) { | |
args.GetReturnValue().Set(ary); | ||
} | ||
|
||
bool HasUnrefedTimerHandles(Environment* env) { | ||
|
||
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. nit: remove empty line. |
||
HandleScope handle_scope(env->isolate()); | ||
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. The |
||
|
||
for (auto w : *env->handle_wrap_queue()) { | ||
if (!w->persistent().IsEmpty() && w->flags_ & HandleWrap::kUnref) | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
|
||
static void Abort(const FunctionCallbackInfo<Value>& args) { | ||
ABORT(); | ||
|
@@ -3969,6 +3981,11 @@ static void StartNodeInstance(void* arg) { | |
v8::platform::PumpMessageLoop(default_platform, isolate); | ||
EmitBeforeExit(env); | ||
|
||
// We need to run an extra event loop turn to purge unrefed handles. | ||
bool unrefedTimers = HasUnrefedTimerHandles(env); | ||
if (unrefedTimers == 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. @trevnorris would it better for me to inline the 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. naw. looks good as it is. |
||
uv_run(env->event_loop(), UV_RUN_NOWAIT); | ||
|
||
// Emit `beforeExit` if the loop became alive either after emitting | ||
// event, or after running some callbacks. | ||
more = uv_loop_alive(env->event_loop()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
|
||
var once = 0; | ||
|
||
process.on('beforeExit', () => { | ||
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. Use |
||
setTimeout(() => {}, 1).unref(); | ||
once++; | ||
}); | ||
|
||
process.on('exit', (code) => { | ||
if (code !== 0) 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. Why ignoring if the process fails? 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. It's not. But if the process has already failed we want that error, not the assertion. |
||
|
||
assert.strictEqual(once, 1); | ||
}); |
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.
nit: more consistent style to have two lines between functions.