Fix reentrant lock bug