Skip to content

Commit c237935

Browse files
committed
fix(sqlite): avoid nested runtime during vfs register
1 parent 5ffa0d0 commit c237935

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

  • engine/packages/depot-client/src

engine/packages/depot-client/src/vfs.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use moka::sync::Cache;
1616
use parking_lot::{Mutex, RwLock};
1717
use rivet_envoy_client::handle::EnvoyHandle;
1818
use rivet_envoy_protocol as protocol;
19-
use tokio::runtime::Handle;
19+
use tokio::runtime::{Handle, RuntimeFlavor};
2020

2121
use crate::optimization_flags::{SqliteOptimizationFlags, sqlite_optimization_flags};
2222

@@ -1549,12 +1549,23 @@ fn fetch_initial_main_page(
15491549
runtime: &Handle,
15501550
actor_id: &str,
15511551
) -> std::result::Result<Option<Vec<u8>>, String> {
1552-
let response = runtime.block_on(transport.get_pages(protocol::SqliteGetPagesRequest {
1553-
actor_id: actor_id.to_string(),
1554-
pgnos: vec![1],
1555-
expected_generation: None,
1556-
expected_head_txid: None,
1557-
}));
1552+
if matches!(runtime.runtime_flavor(), RuntimeFlavor::CurrentThread) {
1553+
return Err(
1554+
"sqlite VFS registration cannot synchronously fetch the initial page on a current-thread Tokio runtime"
1555+
.to_string(),
1556+
);
1557+
}
1558+
// `register` is invoked from inside an async context (e.g. `open_database_from_envoy`),
1559+
// so plain `Handle::block_on` panics. Drop into `block_in_place` to bridge sync VFS
1560+
// registration into the async transport call.
1561+
let response = tokio::task::block_in_place(|| {
1562+
runtime.block_on(transport.get_pages(protocol::SqliteGetPagesRequest {
1563+
actor_id: actor_id.to_string(),
1564+
pgnos: vec![1],
1565+
expected_generation: None,
1566+
expected_head_txid: None,
1567+
}))
1568+
});
15581569

15591570
match response {
15601571
Ok(protocol::SqliteGetPagesResponse::SqliteGetPagesOk(ok)) => Ok(ok

0 commit comments

Comments
 (0)