Ensure unlocking even if errors happen.