closing socket on error