Skip to content

Fix possible concurrency issue in contractset

Christopher Schinnerl requested to merge contractset-concurrency-fix into master

Created by: ChrisSchinnerl

This PR should fix a possible deadlock. A deadlock could happen the following way:

Thread A calls Acquire and gets a contract. Thread B and C also call Acquire and have to wait for the lock of thread A. Thread A calls Delete instead of Return on the contract and unlocks the lock for B but C still has to wait. Thread B gets the contract and does some work. After that it decides to call Delete too. Unfortunately the contract is not in the map anymore. This means we can't find it and don't unlock the lock on it. Thread C waits forever.

The changes in this PR should guarantee that we can't acquire a contract that has been deleted by a different thread while waiting for the contract's lock.

Merge request reports