blib-la / runpod-worker-comfy

ComfyUI as a serverless API on RunPod
GNU Affero General Public License v3.0
298 stars 205 forks source link

Connection Refused #67

Open jarnowu opened 2 months ago

jarnowu commented 2 months ago

I'm running this on Runpod Serverless. Got everything set up nicely following the guide. When I run a request in the serverless UI or from my own api env, I get this:

Error queuing workflow: <urlopen error [Errno 111] Connection refused>

Serverless logs say: runpod-worker-comfy - Failed to connect to server at http://127.0.0.1:8188 after 500 attempts.

Any help? Am I doing something wrong?

jrenzi commented 2 months ago

That's because runpod is trying to connect to your localhost, which is not possible. You have to expose your localhost to the internet. You can do this installing ngrok and starting it, so you will have to use a webhook similar to https://f35d-190-2-96-333.ngrok-free.app

Ngrok generates a new url each time you start it (except you use the paid plan)

jarnowu commented 2 months ago

Oh, did I understand wrong that this comfy solution would work independently on Runpod, without the need for any local environment?

billyberkouwer commented 1 month ago

I can confirm I get the same error occasionally. It usually happens with the initial request, although not every time. Once a new request comes in, it usually starts working. See this error message returned from RunPod:

 {
    "delayTime": 144,
    "error": "{\"error_type\": \"<class 'requests.exceptions.ConnectionError'>\", \"error_message\": \"HTTPConnectionPool(host='127.0.0.1', port=8188): Max retries exceeded with url: /upload/image (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x78d90c244700>: Failed to establish a new connection: [Errno 111] Connection refused'))\", \"error_traceback\": \"Traceback (most recent call last):\\n  File \\\"/usr/local/lib/python3.10/dist-packages/urllib3/connection.py\\\", line 196, in _new_conn\\n    sock = connection.create_connection(\\n  File \\\"/usr/local/lib/python3.10/dist-packages/urllib3/util/connection.py\\\", line 85, in create_connection\\n    raise err\\n  File \\\"/usr/local/lib/python3.10/dist-packages/urllib3/util/connection.py\\\", line 73, in create_connection\\n    sock.connect(sa)\\nConnectionRefusedError: [Errno 111] Connection refused\\n\\nThe above exception was the direct cause of the following exception:\\n\\nTraceback (most recent call last):\\n  File \\\"/usr/local/lib/python3.10/dist-packages/urllib3/connectionpool.py\\\", line 789, in urlopen\\n    response = self._make_request(\\n  File \\\"/usr/local/lib/python3.10/dist-packages/urllib3/connectionpool.py\\\", line 495, in _make_request\\n    conn.request(\\n  File \\\"/usr/local/lib/python3.10/dist-packages/urllib3/connection.py\\\", line 398, in request\\n    self.endheaders()\\n  File \\\"/usr/lib/python3.10/http/client.py\\\", line 1278, in endheaders\\n    self._send_output(message_body, encode_chunked=encode_chunked)\\n  File \\\"/usr/lib/python3.10/http/client.py\\\", line 1038, in _send_output\\n    self.send(msg)\\n  File \\\"/usr/lib/python3.10/http/client.py\\\", line 976, in send\\n    self.connect()\\n  File \\\"/usr/local/lib/python3.10/dist-packages/urllib3/connection.py\\\", line 236, in connect\\n    self.sock = self._new_conn()\\n  File \\\"/usr/local/lib/python3.10/dist-packages/urllib3/connection.py\\\", line 211, in _new_conn\\n    raise NewConnectionError(\\nurllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x78d90c244700>: Failed to establish a new connection: [Errno 111] Connection refused\\n\\nThe above exception was the direct cause of the following exception:\\n\\nTraceback (most recent call last):\\n  File \\\"/usr/local/lib/python3.10/dist-packages/requests/adapters.py\\\", line 667, in send\\n    resp = conn.urlopen(\\n  File \\\"/usr/local/lib/python3.10/dist-packages/urllib3/connectionpool.py\\\", line 843, in urlopen\\n    retries = retries.increment(\\n  File \\\"/usr/local/lib/python3.10/dist-packages/urllib3/util/retry.py\\\", line 519, in increment\\n    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]\\nurllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=8188): Max retries exceeded with url: /upload/image (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x78d90c244700>: Failed to establish a new connection: [Errno 111] Connection refused'))\\n\\nDuring handling of the above exception, another exception occurred:\\n\\nTraceback (most recent call last):\\n  File \\\"/usr/local/lib/python3.10/dist-packages/runpod/serverless/modules/rp_job.py\\\", line 132, in run_job\\n    handler_return = handler(job)\\n  File \\\"/rp_handler.py\\\", line 639, in handler\\n    upload_result = upload_images(images)\\n  File \\\"/rp_handler.py\\\", line 461, in upload_images\\n    response = requests.post(f\\\"http://{COMFY_HOST}/upload/image\\\", files=files)\\n  File \\\"/usr/local/lib/python3.10/dist-packages/requests/api.py\\\", line 115, in post\\n    return request(\\\"post\\\", url, data=data, json=json, **kwargs)\\n  File \\\"/usr/local/lib/python3.10/dist-packages/requests/api.py\\\", line 59, in request\\n    return session.request(method=method, url=url, **kwargs)\\n  File \\\"/usr/local/lib/python3.10/dist-packages/requests/sessions.py\\\", line 589, in request\\n    resp = self.send(prep, **send_kwargs)\\n  File \\\"/usr/local/lib/python3.10/dist-packages/requests/sessions.py\\\", line 703, in send\\n    r = adapter.send(request, **kwargs)\\n  File \\\"/usr/local/lib/python3.10/dist-packages/requests/adapters.py\\\", line 700, in send\\n    raise ConnectionError(e, request=request)\\nrequests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=8188): Max retries exceeded with url: /upload/image (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x78d90c244700>: Failed to establish a new connection: [Errno 111] Connection refused'))\\n\", \"hostname\": \"7c4waly67e070o-64411227\", \"worker_id\": \"7c4waly67e070o\", \"runpod_version\": \"1.7.0\"}",
    "executionTime": 27502,
    "id": "sync-be6af499-d500-4833-a074-1e19879092e4-u1",
    "status": "FAILED",
    "workerId": "7c4waly67e070o"
  }

And this from the RunPod logs:

  {
    "endpointId": "cu0on16gna5q22",
    "workerId": "f1dtg0mk09pkzx",
    "level": "info",
    "message": "runpod-worker-comfy - Failed to connect to server at http://127.0.0.1:8188 after 500 attempts.\n",
    "dt": "2024-09-30 09:19:51.97469504"
  }

I don't recall seeing this in earlier versions, although it may have been present.

Gursehaj-Snap commented 2 weeks ago

I am getting this issue on serverless. Do I need to expose the port? Cause I did try it and it doesn't solve the issue.

2024-11-02T13:20:11.727076429Z [runpod-worker-comfy] API: unreachable.. retrying in 100ms