Deadlocking a Tokio mutex without holding a lock

138 points samyak210 35 comments

I recently ran into a weird bug where a Tokio mutex was unlocked, but no other task was able to acquire it. While debugging this, I learnt a lot about the internals of Tokio's mutexes and semaphores. I wrote up a short blog post on how it happened and the root cause.

To be clear, there's no bug in Tokio. This happened because of the way I messed with Rust futures.