Close socket on error