Skip to content

Commit 452e4ca

Browse files
committed
instance_manager: Call run_subgraph with unconstrained tokio budget
1 parent 4c7c565 commit 452e4ca

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

core/src/subgraph/instance_manager.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use lazy_static::lazy_static;
44
use std::collections::{BTreeSet, HashMap, HashSet};
55
use std::sync::{Arc, RwLock};
66
use std::time::Instant;
7+
use tokio::task;
78

89
use graph::components::ethereum::{triggers_in_block, EthereumNetworks};
910
use graph::components::store::{BlockStore, ModificationsAndCache};
@@ -358,7 +359,7 @@ where
358359
let id = manifest.id.clone();
359360

360361
// `start_subgraph_deployment` is blocking.
361-
tokio::task::spawn_blocking(move || {
362+
task::spawn_blocking(move || {
362363
store
363364
.start_subgraph_deployment(&logger, &id)
364365
.map_err(Error::from)
@@ -445,9 +446,15 @@ where
445446
// block stream and include events for the new data sources going
446447
// forward; this is easier than updating the existing block stream.
447448
//
448-
// This task has many calls to the store, so mark it as `blocking`.
449+
// This is a long-running and unfortunately a blocking future (see #905), so it is run in
450+
// its own thread. It is also run with `task::unconstrained` because we have seen deadlocks
451+
// occur without it, possibly caused by our use of legacy futures and tokio versions in the
452+
// codebase and dependencies, which may not play well with the tokio 1.0 cooperative
453+
// scheduling. It is also logical in terms of performance to run this with `unconstrained`,
454+
// it has a dedicated OS thread so the OS will handle the preemption. See
455+
// https://github.com/tokio-rs/tokio/issues/3493.
449456
graph::spawn_thread(deployment_id.to_string(), move || {
450-
if let Err(e) = graph::block_on(run_subgraph(ctx)) {
457+
if let Err(e) = graph::block_on(task::unconstrained(run_subgraph(ctx))) {
451458
error!(
452459
&logger,
453460
"Subgraph instance failed to run: {}",

0 commit comments

Comments
 (0)