Deal with the case where socket.recv fails, e.g. connection reset by peer.