try to close the socket upon exception