deno_core: 从快照中恢复的 JsRuntimeForSnapshot 进行快照时,会丢弃继承的扩展源;下一次恢复时会发生段错误
//! Repro: snapshotting a runtime that was itself restored from a snapshot //! loses the externalized extension sources; loading the result segfaults. //! //! S0 (fresh, extension loads one lazy script) --snapshot--> S1 //! restore S1 into JsRuntimeForSnapshot, run a cell --snapshot--> S2 //! restore S2 --> SIGSEGV in //! v8::internal::PostProcessExternalString (Deserializer) //! This is a self-contained crate that depends only on deno_core = "0.412.0". use deno_core::{JsRuntime, JsRuntimeForSnapshot, RuntimeOptions};
deno_core::extension!(repro_ext, lazy_loaded_js = ["lazy.js"]);
fn opts(snapshot: Option<&'static [u8]>) -> RuntimeOptions { RuntimeOptions { startup_snapshot: snapshot, extensions: vec![repro_ext::init()], ..Default::default() } }
fn main() { let tokio = tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap(); let _guard = tokio.enter();
// generation 0 -> S1: consume the lazy script so its externalized source
// is referenced from the heap
let s1 = {
let mut rt = JsRuntimeForSnapshot::new(opts(None));
rt.execute_script("a.js", "globalThis.a = Deno.core.loadExtScript('ext:repro_ext/lazy.js')").unwrap();
rt.snapshot()
};
let s1: &'static [u8] = Box::leak(s1);
eprintln!("S1: {} bytes", s1.len());
// restore S1 into a JsRuntimeForSnapshot, run a cell
let rt = JsRuntimeForSnapshot::new(opts(Some(s1)));
rt.execute_script("b.js", "globalThis.a = Deno.core.loadExtScript('ext:repro_ext/lazy.js')").unwrap();
let s2 = rt.snapshot();
let s2: &'static [u8] = Box::leak(s2);
eprintln!("S2: {} bytes", s2.len());
// restore S2
let rt = JsRuntimeForSnapshot::new(opts(Some(s2)));
rt.execute_script("c.js", "globalThis.a = Deno.core.loadExtScript('ext:repro_ext/lazy.js')").unwrap();
}
内容来源: denoland/deno