Fix lock recursion bug