Make sure socket exists before closing.