tokio::sync::Mutex lock().await vs try_lock()
⚓ Rust 📅 2025-09-11 👤 surdeus 👁️ 9Hi community!
Guys I have some code with usage of tokio::sync::Mutex and in the first iteration I used lock().await everywhere. But with growth of code amount I began to get deadlocks and I decided to switch to try_lock() usage and fix logic to avoid deadlocks. And also I have the same usage pattern for tokio::sync::RwLock.
Could you please advice or explain me what potential problems may I have with such approach?
The first thought that I need robust retry mechanism but for now I don't have a good solution for that either.
Thanks in advance ![]()
7 posts - 3 participants
🏷️ Rust_feed