Skip to content

Commit b329fc6

Browse files
committed
fix: shouldn't be initialized the v8 platform from DenoRuntime::new
At the time of invoking `DenoRuntime::new()`, it is a time that already detached from the main thread. The function initializes the V8 platform should be invoked only from the main thread, so it's not right. (cherry picked from commit 989867a)
1 parent 0f6bdfd commit b329fc6

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import_map = { version = "0.15.0" }
6767
base64 = { version = "=0.13.1" }
6868
futures = { version = "0.3.28" }
6969
futures-util = { version = "0.3.28" }
70+
ctor = { version = "0.2.6" }
7071

7172
[profile.release]
7273
lto = true

crates/base/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ log = { workspace = true }
3838
reqwest.workspace = true
3939
serde = { version = "1.0.149", features = ["derive"] }
4040
tokio = { workspace = true }
41-
tokio-util = { workspace = true, features = [ "rt" ] }
41+
tokio-util = { workspace = true, features = ["rt"] }
4242
futures-util = { workspace = true }
4343
url = { version = "2.3.1" }
4444
event_worker ={ version = "0.1.0", path = "../event_worker" }
@@ -59,6 +59,7 @@ enum-as-inner.workspace = true
5959
urlencoding.workspace = true
6060
scopeguard = { version = "1.2.0" }
6161
pin-project = { version = "1.1.3" }
62+
ctor = { workspace = true }
6263

6364
[dev-dependencies]
6465
flaky_test = { version = "0.1.0", path = "../flaky_test" }

crates/base/src/deno_runtime.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::utils::units::mib_to_bytes;
33

44
use anyhow::{anyhow, bail, Context, Error};
55
use cpu_timer::get_thread_time;
6+
use ctor::ctor;
67
use deno_core::error::AnyError;
78
use deno_core::url::Url;
89
use deno_core::{located_script_name, serde_v8, JsRuntime, ModuleCode, ModuleId, RuntimeOptions};
@@ -13,7 +14,6 @@ use deno_tls::rustls_native_certs::load_native_certs;
1314
use deno_tls::RootCertStoreProvider;
1415
use futures_util::future::poll_fn;
1516
use log::{error, trace};
16-
use once_cell::sync::OnceCell;
1717
use sb_core::conn_sync::ConnSync;
1818
use serde::de::DeserializeOwned;
1919
use std::collections::HashMap;
@@ -46,6 +46,16 @@ use sb_node::deno_node;
4646
use sb_workers::context::{UserWorkerMsgs, WorkerContextInitOpts, WorkerRuntimeOpts};
4747
use sb_workers::sb_user_workers;
4848

49+
#[ctor]
50+
fn init_v8_platform() {
51+
set_v8_flags();
52+
53+
// NOTE(denoland/deno/20495): Due to the new PKU (Memory Protection Keys)
54+
// feature introduced in V8 11.6, We need to initialize the V8 platform on
55+
// the main thread that spawns V8 isolates.
56+
JsRuntime::init_platform(None);
57+
}
58+
4959
pub struct DenoRuntimeError(Error);
5060

5161
impl PartialEq for DenoRuntimeError {
@@ -75,17 +85,6 @@ impl DenoRuntime {
7585
#[allow(clippy::unnecessary_literal_unwrap)]
7686
#[allow(clippy::arc_with_non_send_sync)]
7787
pub async fn new(opts: WorkerContextInitOpts) -> Result<Self, Error> {
78-
static INITIALZE_V8_PLATFORM: OnceCell<()> = OnceCell::new();
79-
80-
INITIALZE_V8_PLATFORM.get_or_init(|| {
81-
set_v8_flags();
82-
83-
// NOTE(denoland/deno/20495): Due to the new PKU (Memory Protection Keys)
84-
// feature introduced in V8 11.6, We need to initialize the V8 platform on
85-
// the main thread that spawns V8 isolates.
86-
JsRuntime::init_platform(None);
87-
});
88-
8988
let WorkerContextInitOpts {
9089
service_path,
9190
no_module_cache,

crates/cpu_timer/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ libc = { workspace = true }
1111
nix = { version = "0.26.2", features = ["signal"] }
1212
tokio = { workspace = true }
1313
log = { workspace = true }
14-
ctor = { version = "0.2.6" }
14+
ctor = { workspace = true }
1515
futures = { workspace = true }
1616
signal-hook = { version = "0.3.17" }
1717
signal-hook-tokio = { version = "0.3.1", features = ["futures-v0_3"] }

0 commit comments

Comments
 (0)