Fix problem with intermittent SocketException on shutdown by catching and returning nil.