ENGINE-1844, refactor work to fix lost work issue

The issue came from lock that was stored in local variable but was lost at a time -> no unlock -> process was lock