Fix potential deadlock