Skip to content
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(core): keep event loop alive if there are ticks scheduled #12814

Merged
merged 3 commits into from
Nov 19, 2021

Conversation

bnoordhuis
Copy link
Contributor

Demonstrates that nextTick() callbacks aren't invoked when there isn't
anything else keeping the event loop alive. Specifically:

  1. nextTickCallback is invoked, but
  2. macrotaskCallback is not

Demonstrates that nextTick() callbacks aren't invoked when there isn't
anything else keeping the event loop alive. Specifically:

1. nextTickCallback is invoked, but
2. macrotaskCallback is not
@bnoordhuis
Copy link
Contributor Author

The test is passing after the second commit but I'm sorta confused: the "has tick scheduled" flag is still true but the event loop exits because the macrotask callback says it's done. Is that expected behavior?

@bartlomieju
Copy link
Member

The test is passing after the second commit but I'm sorta confused: the "has tick scheduled" flag is still true but the event loop exits because the macrotask callback says it's done. Is that expected behavior?

I forgot to account for next ticks in keeping event loop alive. We should add an additional check here:

deno/core/runtime.rs

Lines 804 to 822 in c82ce74

let has_pending_ops = !state.pending_ops.is_empty();
let has_pending_dyn_imports = module_map.has_pending_dynamic_imports();
let has_pending_dyn_module_evaluation =
!state.pending_dyn_mod_evaluate.is_empty();
let has_pending_module_evaluation = state.pending_mod_evaluate.is_some();
let has_pending_background_tasks =
self.v8_isolate().has_pending_background_tasks();
let inspector_has_active_sessions = self
.inspector
.as_ref()
.map(|i| i.has_active_sessions())
.unwrap_or(false);
if !has_pending_ops
&& !has_pending_dyn_imports
&& !has_pending_dyn_module_evaluation
&& !has_pending_module_evaluation
&& !has_pending_background_tasks
and keep event loop running

@bartlomieju bartlomieju changed the title wip: add failing nexttick test fix(core): keep event loop alive if there are ticks scheduled Nov 19, 2021
@bartlomieju
Copy link
Member

@bnoordhuis PTAL

@bnoordhuis
Copy link
Contributor Author

LGTM but I can't approve my own PRs. =)

@bartlomieju bartlomieju merged commit 22dcf82 into denoland:main Nov 19, 2021
andreubotella pushed a commit to andreubotella/deno that referenced this pull request Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants