How do I fix this apparent deadlock caused by futures-aware Mutex


#1

Hello all. I’m dabbling in asynchronous programming trying to implement a web crawler. I’m having a problem with figuring out how to resolve a deadlock that pops up in my code. The offending line seems to be at https://github.com/iancormac84/asyncscraper/blob/master/src/main.rs#L135. What’s confusing me is that at this point in the program execution, there shouldn’t be anything stopping the Mutex from being acquired immediately. Maybe I’m wrong. I don’t fully understand the Futures execution model as yet, so I’m obviously committing a no-no. Can someone provide me with some guidance, please? Thanks!


#2

It looks like you’re still holding the lock in crawl_urls at that point, I’m not sure whether futures Mutex is re-entrant, but if you’re getting a deadlock I would guess not.


#3

So in desperation, I had tried using the try_lock method instead, and that caused a stack crash where println debugging showed myriads of nested MutexGuards. Does that confirm your suspicion? And do you have any suggestions on how to fix the deadlock?