Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
timers: check can_call_into_js in Immediates
Do not execute native immediates and prevent infinite loop if it's
possible to call into JS
  • Loading branch information
apapirovski committed May 31, 2018
commit 82d8f8747a19b93af04465c423e745176b74afcf
4 changes: 2 additions & 2 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ void Environment::RunAndClearNativeImmediates() {
void Environment::CheckImmediate(uv_check_t* handle) {
Environment* env = Environment::from_immediate_check_handle(handle);

if (env->immediate_info()->count() == 0)
if (env->immediate_info()->count() == 0 || !env->can_call_into_js())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be right before the do {, because we probably want our native immediate callbacks to still be called – not all of them are calling JS, some or doing cleanup rather than something else

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would that be strictly correct even if it's not calling JS? At least in relation to the main thread (and not workers), the expectation was that no user code would run after EmitExit finishes. After RunCleanup was added that's no longer the case since we run the loop one final time.

Are there are any Immediates that we truly want to have run at this point?

return;

HandleScope scope(env->isolate());
Expand All @@ -472,7 +472,7 @@ void Environment::CheckImmediate(uv_check_t* handle) {
0,
nullptr,
{0, 0}).ToLocalChecked();
} while (env->immediate_info()->has_outstanding());
} while (env->immediate_info()->has_outstanding() && env->can_call_into_js());

if (env->immediate_info()->ref_count() == 0)
env->ToggleImmediateRef(false);
Expand Down