Fix potential infinite wait