diff --git a/Cargo.lock b/Cargo.lock index 443a00036e3..c80852a0bad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -449,7 +449,7 @@ checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" [[package]] name = "cranelift-bforest" version = "0.63.0" -source = "git+https://github.com/leoyvens/wasmtime.git?branch=from-error-for-trap#26edb6de9bfa986a5acb8b29924912388e68929e" +source = "git+https://github.com/yurydelendik/wasmtime.git?branch=mv-sig-registry#4cefa4a17a032256c3a7d4f9937378129a31d97b" dependencies = [ "cranelift-entity", ] @@ -457,7 +457,7 @@ dependencies = [ [[package]] name = "cranelift-codegen" version = "0.63.0" -source = "git+https://github.com/leoyvens/wasmtime.git?branch=from-error-for-trap#26edb6de9bfa986a5acb8b29924912388e68929e" +source = "git+https://github.com/yurydelendik/wasmtime.git?branch=mv-sig-registry#4cefa4a17a032256c3a7d4f9937378129a31d97b" dependencies = [ "byteorder", "cranelift-bforest", @@ -476,7 +476,7 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" version = "0.63.0" -source = "git+https://github.com/leoyvens/wasmtime.git?branch=from-error-for-trap#26edb6de9bfa986a5acb8b29924912388e68929e" +source = "git+https://github.com/yurydelendik/wasmtime.git?branch=mv-sig-registry#4cefa4a17a032256c3a7d4f9937378129a31d97b" dependencies = [ "cranelift-codegen-shared", "cranelift-entity", @@ -485,12 +485,12 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" version = "0.63.0" -source = "git+https://github.com/leoyvens/wasmtime.git?branch=from-error-for-trap#26edb6de9bfa986a5acb8b29924912388e68929e" +source = "git+https://github.com/yurydelendik/wasmtime.git?branch=mv-sig-registry#4cefa4a17a032256c3a7d4f9937378129a31d97b" [[package]] name = "cranelift-entity" version = "0.63.0" -source = "git+https://github.com/leoyvens/wasmtime.git?branch=from-error-for-trap#26edb6de9bfa986a5acb8b29924912388e68929e" +source = "git+https://github.com/yurydelendik/wasmtime.git?branch=mv-sig-registry#4cefa4a17a032256c3a7d4f9937378129a31d97b" dependencies = [ "serde", ] @@ -498,7 +498,7 @@ dependencies = [ [[package]] name = "cranelift-frontend" version = "0.63.0" -source = "git+https://github.com/leoyvens/wasmtime.git?branch=from-error-for-trap#26edb6de9bfa986a5acb8b29924912388e68929e" +source = "git+https://github.com/yurydelendik/wasmtime.git?branch=mv-sig-registry#4cefa4a17a032256c3a7d4f9937378129a31d97b" dependencies = [ "cranelift-codegen", "log 0.4.8", @@ -509,7 +509,7 @@ dependencies = [ [[package]] name = "cranelift-native" version = "0.63.0" -source = "git+https://github.com/leoyvens/wasmtime.git?branch=from-error-for-trap#26edb6de9bfa986a5acb8b29924912388e68929e" +source = "git+https://github.com/yurydelendik/wasmtime.git?branch=mv-sig-registry#4cefa4a17a032256c3a7d4f9937378129a31d97b" dependencies = [ "cranelift-codegen", "raw-cpuid", @@ -519,7 +519,7 @@ dependencies = [ [[package]] name = "cranelift-wasm" version = "0.63.0" -source = "git+https://github.com/leoyvens/wasmtime.git?branch=from-error-for-trap#26edb6de9bfa986a5acb8b29924912388e68929e" +source = "git+https://github.com/yurydelendik/wasmtime.git?branch=mv-sig-registry#4cefa4a17a032256c3a7d4f9937378129a31d97b" dependencies = [ "cranelift-codegen", "cranelift-entity", @@ -4590,7 +4590,7 @@ checksum = "af931e2e1960c53f4a28b063fec4cacd036f35acbec8ff3a4739125b17382a87" [[package]] name = "wasmtime" version = "0.16.0" -source = "git+https://github.com/leoyvens/wasmtime.git?branch=from-error-for-trap#26edb6de9bfa986a5acb8b29924912388e68929e" +source = "git+https://github.com/yurydelendik/wasmtime.git?branch=mv-sig-registry#4cefa4a17a032256c3a7d4f9937378129a31d97b" dependencies = [ "anyhow", "backtrace", @@ -4613,7 +4613,7 @@ dependencies = [ [[package]] name = "wasmtime-debug" version = "0.16.0" -source = "git+https://github.com/leoyvens/wasmtime.git?branch=from-error-for-trap#26edb6de9bfa986a5acb8b29924912388e68929e" +source = "git+https://github.com/yurydelendik/wasmtime.git?branch=mv-sig-registry#4cefa4a17a032256c3a7d4f9937378129a31d97b" dependencies = [ "anyhow", "faerie", @@ -4628,7 +4628,7 @@ dependencies = [ [[package]] name = "wasmtime-environ" version = "0.16.0" -source = "git+https://github.com/leoyvens/wasmtime.git?branch=from-error-for-trap#26edb6de9bfa986a5acb8b29924912388e68929e" +source = "git+https://github.com/yurydelendik/wasmtime.git?branch=mv-sig-registry#4cefa4a17a032256c3a7d4f9937378129a31d97b" dependencies = [ "anyhow", "base64 0.12.1", @@ -4656,7 +4656,7 @@ dependencies = [ [[package]] name = "wasmtime-jit" version = "0.16.0" -source = "git+https://github.com/leoyvens/wasmtime.git?branch=from-error-for-trap#26edb6de9bfa986a5acb8b29924912388e68929e" +source = "git+https://github.com/yurydelendik/wasmtime.git?branch=mv-sig-registry#4cefa4a17a032256c3a7d4f9937378129a31d97b" dependencies = [ "anyhow", "cfg-if", @@ -4682,7 +4682,7 @@ dependencies = [ [[package]] name = "wasmtime-profiling" version = "0.16.0" -source = "git+https://github.com/leoyvens/wasmtime.git?branch=from-error-for-trap#26edb6de9bfa986a5acb8b29924912388e68929e" +source = "git+https://github.com/yurydelendik/wasmtime.git?branch=mv-sig-registry#4cefa4a17a032256c3a7d4f9937378129a31d97b" dependencies = [ "anyhow", "cfg-if", @@ -4700,12 +4700,13 @@ dependencies = [ [[package]] name = "wasmtime-runtime" version = "0.16.0" -source = "git+https://github.com/leoyvens/wasmtime.git?branch=from-error-for-trap#26edb6de9bfa986a5acb8b29924912388e68929e" +source = "git+https://github.com/yurydelendik/wasmtime.git?branch=mv-sig-registry#4cefa4a17a032256c3a7d4f9937378129a31d97b" dependencies = [ "backtrace", "cc", "cfg-if", "indexmap", + "lazy_static", "libc", "memoffset", "more-asserts", diff --git a/core/src/subgraph/instance_manager.rs b/core/src/subgraph/instance_manager.rs index f081919c860..f6d671be552 100644 --- a/core/src/subgraph/instance_manager.rs +++ b/core/src/subgraph/instance_manager.rs @@ -909,12 +909,12 @@ async fn process_triggers format_err!( - "Failed to process trigger in block {}, transaction {:x}: {}", + "Failed to process trigger in block {}, transaction {:x}: {:#}", block_ptr, tx_hash, e ), - None => format_err!("Failed to process trigger: {}", e), + None => format_err!("Failed to process trigger: {:#}", e), })?; let elapsed = start.elapsed().as_secs_f64(); subgraph_metrics.observe_trigger_processing_duration(elapsed, trigger_type); diff --git a/graphql/src/subscription/mod.rs b/graphql/src/subscription/mod.rs index 23d7c8d320d..c97bb5bb752 100644 --- a/graphql/src/subscription/mod.rs +++ b/graphql/src/subscription/mod.rs @@ -167,7 +167,7 @@ fn map_source_to_response_stream( resolver.clone(), query.clone(), event, - timeout.clone(), + timeout, max_first, ) .boxed(), diff --git a/runtime/wasm/Cargo.toml b/runtime/wasm/Cargo.toml index 6110e62c18a..7e4f3b9ac90 100644 --- a/runtime/wasm/Cargo.toml +++ b/runtime/wasm/Cargo.toml @@ -24,7 +24,7 @@ bytes = "0.5" # PR is merged. https://github.com/rustonaut/maybe-owned/pull/9 # See also 92cd8019-0136-4011-96a0-40b3eec37f73 maybe-owned = { git = "https://github.com/rustonaut/maybe-owned", branch = "master" } -wasmtime = { git = "https://github.com/leoyvens/wasmtime.git", branch = "from-error-for-trap" } +wasmtime = { git = "https://github.com/yurydelendik/wasmtime.git", branch = "mv-sig-registry" } [dev-dependencies] graphql-parser = "0.2.3" diff --git a/runtime/wasm/src/host_exports.rs b/runtime/wasm/src/host_exports.rs index 3e5c3007f2d..fe06733e732 100644 --- a/runtime/wasm/src/host_exports.rs +++ b/runtime/wasm/src/host_exports.rs @@ -389,7 +389,7 @@ impl HostExports { valid_module.clone(), ctx.derive_with_empty_block_state(), host_metrics.clone(), - module.timeout.clone(), + module.timeout, )?; let result = module.handle_json_callback(&callback, &sv.value, &user_data)?; // Log progress every 15s diff --git a/runtime/wasm/src/mapping.rs b/runtime/wasm/src/mapping.rs index ff43b549a2a..0cb500270ac 100644 --- a/runtime/wasm/src/mapping.rs +++ b/runtime/wasm/src/mapping.rs @@ -21,6 +21,8 @@ pub fn spawn_module( runtime: tokio::runtime::Handle, timeout: Option, ) -> Result, anyhow::Error> { + let valid_module = Arc::new(ValidModule::new(&raw_module).unwrap()); + // Create channel for event handling requests let (mapping_request_sender, mapping_request_receiver) = mpsc::channel(100); @@ -33,7 +35,6 @@ pub fn spawn_module( let conf = thread::Builder::new().name(format!("mapping-{}-{}", &subgraph_id, uuid::Uuid::new_v4())); conf.spawn(move || { - let valid_module = Arc::new(ValidModule::new(&raw_module).unwrap()); runtime.enter(|| { // Pass incoming triggers to the WASM module and return entity changes; // Stop when canceled because all RuntimeHosts and their senders were dropped. @@ -181,9 +182,8 @@ impl ValidModule { config.strategy(wasmtime::Strategy::Cranelift).unwrap(); config.interruptable(true); // For timeouts. config.cranelift_nan_canonicalization(true); // For NaN determinism. - - let store = wasmtime::Store::new(&wasmtime::Engine::new(&config)); - let module = wasmtime::Module::from_binary(&store, raw_module)?; + let engine = &wasmtime::Engine::new(&config); + let module = wasmtime::Module::from_binary(&engine, raw_module)?; let mut import_name_to_modules: BTreeMap> = BTreeMap::new(); for (name, module) in module diff --git a/runtime/wasm/src/module/mod.rs b/runtime/wasm/src/module/mod.rs index 462b8c29455..fe221a0966b 100644 --- a/runtime/wasm/src/module/mod.rs +++ b/runtime/wasm/src/module/mod.rs @@ -31,6 +31,8 @@ use into_wasm_ret::IntoWasmRet; #[cfg(test)] mod test; +const TRAP_TIMEOUT: &str = "trap: interrupt"; + /// Handle to a WASM instance, which is terminated if and only if this is dropped. pub(crate) struct WasmInstanceHandle { // This is the only reference to `WasmInstance` that's not within the instance itself, @@ -177,8 +179,20 @@ impl WasmInstanceHandle { .get_func(handler) .with_context(|| format!("function {} not found", handler))?; - func.get1()?(arg.wasm_ptr()) - .with_context(|| format!("Failed to invoke handler '{}'", handler)) + func.get1()?(arg.wasm_ptr()).map_err(|e| { + if e.to_string().contains(TRAP_TIMEOUT) { + anyhow::Error::context( + e.into(), + format!( + "Handler '{}' hit the timeout of '{}' seconds", + handler, + self.instance().timeout.unwrap().as_secs() + ), + ) + } else { + anyhow::Error::context(e.into(), format!("Failed to invoke handler '{}'", handler)) + } + }) } } @@ -210,7 +224,7 @@ impl WasmInstance { host_metrics: Arc, timeout: Option, ) -> Result { - let mut linker = wasmtime::Linker::new(valid_module.module.store()); + let mut linker = wasmtime::Linker::new(&wasmtime::Store::new(valid_module.module.engine())); // Used by exports to access the instance context. It is `None` while the module is not yet // instantiated. A desirable consequence is that start function cannot access host exports. @@ -391,7 +405,7 @@ impl WasmInstance { .get1()?; let should_interrupt = Arc::new(AtomicBool::new(true)); - if let Some(timeout) = timeout.clone() { + if let Some(timeout) = timeout { // This task is likely to outlive the instance, which is fine. let interrupt_handle = instance.store().interrupt_handle().unwrap(); let should_interrupt = should_interrupt.clone(); diff --git a/runtime/wasm/src/module/test/abi.rs b/runtime/wasm/src/module/test/abi.rs index fcba95091ee..55ae646f2b5 100644 --- a/runtime/wasm/src/module/test/abi.rs +++ b/runtime/wasm/src/module/test/abi.rs @@ -10,7 +10,7 @@ async fn unbounded_loop() { ); let func = module.get_func("loop").get0().unwrap(); let res: Result<(), _> = func(); - assert!(res.unwrap_err().to_string().contains("interrupt")); + assert!(res.unwrap_err().to_string().contains(TRAP_TIMEOUT)); } #[tokio::test]