Fix race condition with early lock release