Fix bug: unlock when exception