retrying failed socket errors only a certain number of times, as opposed to indefinitely