DeFiCh / ain

DeFi Blockchain - enabling decentralized finance on Bitcoin
https://defichain.com
MIT License
408 stars 122 forks source link

Ensure using deadlock avoidance mechanism on mutex acquiring #368

Closed bvbfan closed 3 years ago

bvbfan commented 3 years ago

What happened:

Currently acquire more than one recursive mutex is ordered, that means acquiring same mutexes in other thread in different / reverse order cause a deadlock

What you expected to happen:

No deadlock on reverse order mutex acquiring

How to reproduce it (as minimally and precisely as possible):

Time |      Thread A      |     Thread B
t1   | Attempt to lock L1 | Attempt to lock L2
t2   |    Gets lock L1    |    Gets lock L2
t3   |      In cs L1      |      In cs L2 
t4   | Attempt to lock L2 | Attempt to lock L1
t5   |     Block on L2    |     Block on L1
<waits forever: deadlock> | <waits forever: deadlock>

Anything else we need to know?:

You can read more on ABBA deadlock

defichain-bot commented 3 years ago

@bvbfan: Thanks for opening an issue, it is currently awaiting triage.

The triage/accepted label can be added by foundation members by writing /triage accepted in a comment.

Details I am a bot created to help the [DeFiCh](https://github.com/DeFiCh) developers manage community feedback and contributions. You can check out my [manifest file](https://github.com/DeFiCh/ain/blob/master/.github/governance.yml) to understand my behavior and what I can do. If you want to use this for your project, you can check out the [DeFiCh/oss-governance-bot](https://github.com/DeFiCh/oss-governance-bot) repository.