Add retry logic to handle dodgy connections

This will also fix problems with us trying to query the state of a
replica set that's in a state transition