Fix race condition in ping-all

Factored ensure-connected out of ping because it doesn't behave well in
parallel (more than one connection attempt).