Add protection against permanent sync locking
Update unit tests for sync locking.