Fix deadlock bug