Skip to content

Commit a96775c

Browse files
committed
runtime: Remove unnecessary block_in_place + block_on
Subgraph runners execute on dedicated OS threads inside graph::block_on(runner.run()), so process_mapping_trigger is already in a valid async context. The block_in_place + block_on combo only existed to allow the nested block_on call, but since all WASM host functions are async and use .await, there is no need to exit and re-enter the runtime context. Replace with a direct .await using FutureExt::catch_unwind for panic recovery.
1 parent 1056bc5 commit a96775c

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

runtime/wasm/src/host.rs

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use std::cmp::PartialEq;
2-
use std::panic;
2+
use std::panic::AssertUnwindSafe;
33
use std::time::Instant;
44

55
use anyhow::Context;
66
use async_trait::async_trait;
7+
use graph::futures03::FutureExt as _;
78

89
use graph::blockchain::{Blockchain, HostFn, RuntimeAdapter};
910
use graph::components::store::{EnsLookup, SubgraphFork};
@@ -194,31 +195,26 @@ where
194195
let logger_for_panic = logger.cheap_clone();
195196
let metrics_for_trigger = metrics.cheap_clone();
196197

197-
// Run the WASM instantiation and handler inside block_in_place.
198-
// This tells tokio "I'm about to block" so it can move async work
199-
// to other threads, preventing executor starvation.
200-
let result = tokio::task::block_in_place(|| {
201-
let handle_fut = async {
202-
let _section = metrics_for_trigger.stopwatch.start_section("module_init");
203-
let module = crate::module::WasmInstance::from_valid_module_with_ctx(
204-
valid_module,
205-
ctx,
206-
metrics_for_trigger.cheap_clone(),
207-
experimental_features,
208-
)
209-
.await
210-
.context("module instantiation failed")?;
211-
drop(_section);
212-
213-
let _section = metrics_for_trigger.stopwatch.start_section("run_handler");
214-
if ENV_VARS.log_trigger_data {
215-
debug!(logger_for_panic, "trigger data: {:?}", trigger);
216-
}
217-
module.handle_trigger(trigger).await
218-
};
219-
220-
panic::catch_unwind(panic::AssertUnwindSafe(|| graph::block_on(handle_fut)))
221-
});
198+
let handle_fut = async {
199+
let _section = metrics_for_trigger.stopwatch.start_section("module_init");
200+
let module = crate::module::WasmInstance::from_valid_module_with_ctx(
201+
valid_module,
202+
ctx,
203+
metrics_for_trigger.cheap_clone(),
204+
experimental_features,
205+
)
206+
.await
207+
.context("module instantiation failed")?;
208+
drop(_section);
209+
210+
let _section = metrics_for_trigger.stopwatch.start_section("run_handler");
211+
if ENV_VARS.log_trigger_data {
212+
debug!(logger_for_panic, "trigger data: {:?}", trigger);
213+
}
214+
module.handle_trigger(trigger).await
215+
};
216+
217+
let result = AssertUnwindSafe(handle_fut).catch_unwind().await;
222218

223219
let result = match result {
224220
Ok(result) => result,

0 commit comments

Comments
 (0)