Do not use recursion for file locking. BUGZ-4147
Begin arcbot message
This merge request is automatically cherrypicked from !1675 (merged) from source branch https://source.coderefinery.org/aleksandr.konstantinov/arc/-/tree/file_lock_fix orginally made by @aleksandr.konstantinov .
The original MR went to branch: https://source.coderefinery.org/nordugrid/arc/-/tree/next
End arcbot message
Code is changed to use loop instead of recursion. Should prevent a-rex from crashing when stack is exhausted.