Added handling of socket.error to tryXTimes