MODE-2190 Fixed the way locks are cleaned up and added some more safeguard checks in the case locks are removed concurrently.
Merge pull request #1110 from hchiorean/MODE-2190-3.x

MODE 2190 - Fixed the way locks are cleaned up and added some more safe guard checks in the case locks are removed concurrently.