Fix blocking_lock panic inside async runtime, reduce pool to 4 connections
spawn_with_arc used blocking_lock() which panics inside tokio runtime. Changed to async lock().await. Reduced StoragePool from 8 to 4 connections for Android compatibility. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
43adbbdf7d
commit
7b9edc13da
3 changed files with 7 additions and 7 deletions
|
|
@ -7281,12 +7281,11 @@ pub struct ConnectionActor {
|
|||
impl ConnectionActor {
|
||||
/// Spawn the actor wrapping a shared Arc<Mutex<CM>>, returning a ConnHandle.
|
||||
/// During migration, both the actor and legacy lock-callers share state.
|
||||
pub fn spawn_with_arc(cm: Arc<Mutex<ConnectionManager>>) -> ConnHandle {
|
||||
pub async fn spawn_with_arc(cm: Arc<Mutex<ConnectionManager>>) -> ConnHandle {
|
||||
let (tx, rx) = mpsc::channel(256);
|
||||
// Hoist frequently-needed Arcs so handlers can skip the conn_mgr lock
|
||||
let (storage, blob_store, endpoint, our_node_id, activity_log, is_anchor) = {
|
||||
// Brief lock just to clone the Arcs
|
||||
let cm_guard = cm.blocking_lock();
|
||||
let cm_guard = cm.lock().await;
|
||||
(
|
||||
Arc::clone(&cm_guard.storage),
|
||||
Arc::clone(&cm_guard.blob_store),
|
||||
|
|
@ -7302,8 +7301,8 @@ impl ConnectionActor {
|
|||
}
|
||||
|
||||
/// Spawn the actor owning the ConnectionManager directly (Phase 5+).
|
||||
pub fn spawn(cm: ConnectionManager) -> ConnHandle {
|
||||
Self::spawn_with_arc(Arc::new(Mutex::new(cm)))
|
||||
pub async fn spawn(cm: ConnectionManager) -> ConnHandle {
|
||||
Self::spawn_with_arc(Arc::new(Mutex::new(cm))).await
|
||||
}
|
||||
|
||||
async fn run(mut self) {
|
||||
|
|
|
|||
|
|
@ -219,7 +219,7 @@ impl Network {
|
|||
let conn_mgr = Arc::new(Mutex::new(conn_mgr));
|
||||
|
||||
// Spawn actor wrapping the same Arc<Mutex<CM>> (Phase 1: additive)
|
||||
let conn_handle = ConnectionActor::spawn_with_arc(Arc::clone(&conn_mgr));
|
||||
let conn_handle = ConnectionActor::spawn_with_arc(Arc::clone(&conn_mgr)).await;
|
||||
|
||||
// TCP UPnP mapping for HTTP post delivery (only if UDP UPnP succeeded)
|
||||
let has_upnp_tcp = if let Some(ref mapping) = upnp_mapping {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,8 @@ pub struct StoragePool {
|
|||
slots: Vec<tokio::sync::Mutex<Storage>>,
|
||||
}
|
||||
|
||||
const STORAGE_POOL_SIZE: usize = 8;
|
||||
/// Pool size: 4 connections balances parallelism with resource constraints (Android fd limits).
|
||||
const STORAGE_POOL_SIZE: usize = 4;
|
||||
|
||||
impl StoragePool {
|
||||
/// Create a pool of Storage connections to the same database.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue