|
1 | 1 | use std::cmp::PartialEq; |
2 | | -use std::panic; |
| 2 | +use std::panic::AssertUnwindSafe; |
3 | 3 | use std::time::Instant; |
4 | 4 |
|
5 | 5 | use anyhow::Context; |
6 | 6 | use async_trait::async_trait; |
| 7 | +use graph::futures03::FutureExt as _; |
7 | 8 |
|
8 | 9 | use graph::blockchain::{Blockchain, HostFn, RuntimeAdapter}; |
9 | 10 | use graph::components::store::{EnsLookup, SubgraphFork}; |
@@ -194,31 +195,26 @@ where |
194 | 195 | let logger_for_panic = logger.cheap_clone(); |
195 | 196 | let metrics_for_trigger = metrics.cheap_clone(); |
196 | 197 |
|
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; |
222 | 218 |
|
223 | 219 | let result = match result { |
224 | 220 | Ok(result) => result, |
|
0 commit comments