Arc<Mutex> deadlock in an async handler
I have an axum 0.7 handler that locks an Arc<Mutex<HashMap>>, then does an async DB call while still holding the guard. Under load the whole service stalls. Reduced version:
let mut map = state.map.lock().unwrap();
let row = db.fetch(&key).await?;
map.insert(key, row);
No error message, just requests hanging. Someone mentioned I'm holding a std Mutex guard across an await. Is that really a deadlock or just slow?
4 replies