[SCALABILITY] Sync Mutex in Async Context (Job State) #21

Open
opened 2026-02-14 21:24:56 +00:00 by thabeta · 0 comments
Owner

In src/server/handlers.rs, the jobs_state is managed using a standard std::sync::Mutex (Line 216):

state.jobs_state.lock().expect("failed to lock state").insert(...)

Risk: Locking a synchronous mutex in an async function (especially one using tokio::spawn) can block the entire Tokio executor thread if a thread holds the lock for too long, essentially "starving" other concurrent tasks.

Fix: Replace std::sync::Mutex with tokio::sync::Mutex or use an actor pattern/dashmap to handle the job state concurrently without blocking executors.

In `src/server/handlers.rs`, the `jobs_state` is managed using a standard `std::sync::Mutex` (Line 216): ```rust state.jobs_state.lock().expect("failed to lock state").insert(...) ``` **Risk:** Locking a synchronous mutex in an `async` function (especially one using `tokio::spawn`) can block the entire Tokio executor thread if a thread holds the lock for too long, essentially "starving" other concurrent tasks. **Fix:** Replace `std::sync::Mutex` with `tokio::sync::Mutex` or use an actor pattern/dashmap to handle the job state concurrently without blocking executors.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
geomind_code/my_fs#21
No description provided.