fix silly deadlock, make more resilient