Do proper error handling if the socket is closed