Skip to content

Commit

Permalink
Fix 100% CPU idling problem by reverting denoland#7672 (denoland#7911)
Browse files Browse the repository at this point in the history
* Revert "refactor: Worker is not a Future (denoland#7895)"

This reverts commit f4357f0.

* Revert "refactor(core): JsRuntime is not a Future (denoland#7855)"

This reverts commit d8879fe.

* Revert "fix(core): module execution with top level await (denoland#7672)"

This reverts commit c7c7677.
  • Loading branch information
ry authored and iykekings committed Oct 10, 2020
1 parent 57496b8 commit 19846bc
Show file tree
Hide file tree
Showing 17 changed files with 222 additions and 492 deletions.
4 changes: 3 additions & 1 deletion cli/coverage.rs
@@ -1,6 +1,7 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.

use crate::colors;
use crate::inspector::DenoInspector;
use crate::inspector::InspectorSession;
use deno_core::error::AnyError;
use deno_core::serde_json;
Expand All @@ -13,7 +14,8 @@ pub struct CoverageCollector {
}

impl CoverageCollector {
pub fn new(session: Box<InspectorSession>) -> Self {
pub fn new(inspector_ptr: *mut DenoInspector) -> Self {
let session = InspectorSession::new(inspector_ptr);
Self { session }
}

Expand Down
22 changes: 13 additions & 9 deletions cli/main.rs
Expand Up @@ -310,7 +310,7 @@ async fn eval_command(
debug!("main_module {}", &main_module);
worker.execute_module(&main_module).await?;
worker.execute("window.dispatchEvent(new Event('load'))")?;
worker.run_event_loop().await?;
(&mut *worker).await?;
worker.execute("window.dispatchEvent(new Event('unload'))")?;
Ok(())
}
Expand Down Expand Up @@ -424,7 +424,7 @@ async fn run_repl(flags: Flags) -> Result<(), AnyError> {
ModuleSpecifier::resolve_url_or_path("./$deno$repl.ts").unwrap();
let global_state = GlobalState::new(flags)?;
let mut worker = MainWorker::new(&global_state, main_module.clone());
worker.run_event_loop().await?;
(&mut *worker).await?;

repl::run(&global_state, worker).await
}
Expand Down Expand Up @@ -455,7 +455,7 @@ async fn run_from_stdin(flags: Flags) -> Result<(), AnyError> {
debug!("main_module {}", main_module);
worker.execute_module(&main_module).await?;
worker.execute("window.dispatchEvent(new Event('load'))")?;
worker.run_event_loop().await?;
(&mut *worker).await?;
worker.execute("window.dispatchEvent(new Event('unload'))")?;
Ok(())
}
Expand Down Expand Up @@ -501,7 +501,7 @@ async fn run_with_watch(flags: Flags, script: String) -> Result<(), AnyError> {
debug!("main_module {}", main_module);
worker.execute_module(&main_module).await?;
worker.execute("window.dispatchEvent(new Event('load'))")?;
worker.run_event_loop().await?;
(&mut *worker).await?;
worker.execute("window.dispatchEvent(new Event('unload'))")?;
Ok(())
}
Expand All @@ -526,7 +526,7 @@ async fn run_command(flags: Flags, script: String) -> Result<(), AnyError> {
debug!("main_module {}", main_module);
worker.execute_module(&main_module).await?;
worker.execute("window.dispatchEvent(new Event('load'))")?;
worker.run_event_loop().await?;
(&mut *worker).await?;
worker.execute("window.dispatchEvent(new Event('unload'))")?;
Ok(())
}
Expand Down Expand Up @@ -596,8 +596,12 @@ async fn test_command(
.save_source_file_in_cache(&main_module, source_file);

let mut maybe_coverage_collector = if flags.coverage {
let session = worker.create_inspector_session();
let mut coverage_collector = CoverageCollector::new(session);
let inspector = worker
.inspector
.as_mut()
.expect("Inspector is not created.");

let mut coverage_collector = CoverageCollector::new(&mut **inspector);
coverage_collector.start_collecting().await?;

Some(coverage_collector)
Expand All @@ -608,9 +612,9 @@ async fn test_command(
let execute_result = worker.execute_module(&main_module).await;
execute_result?;
worker.execute("window.dispatchEvent(new Event('load'))")?;
worker.run_event_loop().await?;
(&mut *worker).await?;
worker.execute("window.dispatchEvent(new Event('unload'))")?;
worker.run_event_loop().await?;
(&mut *worker).await?;

if let Some(coverage_collector) = maybe_coverage_collector.as_mut() {
let coverages = coverage_collector.collect().await?;
Expand Down
10 changes: 1 addition & 9 deletions cli/ops/worker_host.rs
Expand Up @@ -155,13 +155,6 @@ fn run_worker_thread(

if let Err(e) = result {
let mut sender = worker.internal_channels.sender.clone();

// If sender is closed it means that worker has already been closed from
// within using "globalThis.close()"
if sender.is_closed() {
return;
}

sender
.try_send(WorkerEvent::TerminalError(e))
.expect("Failed to post message to host");
Expand All @@ -173,8 +166,7 @@ fn run_worker_thread(
// TODO(bartlomieju): this thread should return result of event loop
// that means that we should store JoinHandle to thread to ensure
// that it actually terminates.
rt.block_on(worker.run_event_loop())
.expect("Panic in event loop");
rt.block_on(worker).expect("Panic in event loop");
debug!("Worker thread shuts down {}", &name);
})?;

Expand Down
11 changes: 8 additions & 3 deletions cli/repl.rs
Expand Up @@ -47,7 +47,7 @@ async fn post_message_and_poll(
return result
}

_ = worker.run_event_loop() => {
_ = &mut *worker => {
// A zero delay is long enough to yield the thread in order to prevent the loop from
// running hot for messages that are taking longer to resolve like for example an
// evaluation of top level await.
Expand Down Expand Up @@ -75,7 +75,7 @@ async fn read_line_and_poll(
result = &mut line => {
return result.unwrap();
}
_ = worker.run_event_loop(), if poll_worker => {
_ = &mut *worker, if poll_worker => {
poll_worker = false;
}
_ = &mut timeout => {
Expand All @@ -92,7 +92,12 @@ pub async fn run(
// Our inspector is unable to default to the default context id so we have to specify it here.
let context_id: u32 = 1;

let mut session = worker.create_inspector_session();
let inspector = worker
.inspector
.as_mut()
.expect("Inspector is not created.");

let mut session = InspectorSession::new(&mut **inspector);

let history_file = global_state.dir.root.join("deno_history.txt");

Expand Down
10 changes: 0 additions & 10 deletions cli/tests/integration_tests.rs
Expand Up @@ -2662,16 +2662,6 @@ itest!(ignore_require {
exit_code: 0,
});

itest!(top_level_await_bug {
args: "run --allow-read top_level_await_bug.js",
output: "top_level_await_bug.out",
});

itest!(top_level_await_bug2 {
args: "run --allow-read top_level_await_bug2.js",
output: "top_level_await_bug2.out",
});

#[test]
fn cafile_env_fetch() {
use deno_core::url::Url;
Expand Down
2 changes: 0 additions & 2 deletions cli/tests/top_level_await_bug.js

This file was deleted.

1 change: 0 additions & 1 deletion cli/tests/top_level_await_bug.out

This file was deleted.

15 changes: 0 additions & 15 deletions cli/tests/top_level_await_bug2.js

This file was deleted.

4 changes: 0 additions & 4 deletions cli/tests/top_level_await_bug2.out

This file was deleted.

5 changes: 0 additions & 5 deletions cli/tests/top_level_await_bug_nested.js

This file was deleted.

0 comments on commit 19846bc

Please sign in to comment.