text-generation-webui icon indicating copy to clipboard operation
text-generation-webui copied to clipboard

Cloudflared server not starting

Open mnt4 opened this issue 1 year ago • 5 comments

Describe the bug

Adding --public-api to the flags causes a traceback instead of starting a cloudflared server. flask-clouflared is installed separately, despite not being included in requirements.txt

Is there an existing issue for this?

  • [X] I have searched the existing issues

Reproduction

  1. Install flask-cloudflared
  2. Run python server.py --share --model_type llama --no-stream --api --public-api --wbits 4 --groupsize 128
  3. Get a Traceback error

Screenshot

No response

Logs

Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 980, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.9/threading.py", line 917, in run
    self._target(*self._args, **self._kwargs)
  File "/content/drive/MyDrive/text-generation-webui/extensions/api/util.py", line 69, in _start_cloudflared
Exception in thread Thread-5:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 980, in _bootstrap_inner
    raise Exception('Could not start cloudflared.')
Exception: Could not start cloudflared.
    self.run()
  File "/usr/lib/python3.9/threading.py", line 917, in run
    self._target(*self._args, **self._kwargs)
  File "/content/drive/MyDrive/text-generation-webui/extensions/api/util.py", line 69, in _start_cloudflared
    raise Exception('Could not start cloudflared.')
Exception: Could not start cloudflared.

System Info

Google Colab

mnt4 avatar Apr 24 '23 23:04 mnt4

Same issue

TruthSearchers avatar Apr 25 '23 04:04 TruthSearchers

The API extension hides the real error, which is

OSError: [Errno 8] Exec format error: '/tmp/cloudflared-linux-amd64'

It looks like cloudfare messed up their reverse proxy executable. It should fix itself eventually

oobabooga avatar Apr 25 '23 06:04 oobabooga

I made a fork of flask_cloudflared that fixes the issue temporarily It can be used via pip install git+https://github.com/mnt4/flask-cloudflared

mnt4 avatar Apr 25 '23 08:04 mnt4

It's working fine now bro thanks ☺️

TruthSearchers avatar Apr 25 '23 10:04 TruthSearchers

I'm getting the same issue

I made a fork of flask_cloudflared that fixes the issue temporarily It can be used via pip install git+https://github.com/mnt4/flask-cloudflared

I'm using the one click install version, running the command doesn't fix it

laughinggaschambers avatar May 11 '23 11:05 laughinggaschambers

The real issue why this bug is happening is that both the blocking api and then streaming api start the _run_cloudflared more or less at the same time, and if this file '/tmp/cloudflared-linux-amd64' is not downloaded and ready fast enough, they collide as the file is still downloading. This is only a working theory, but on my host machine it had no problem, but as soon as this was running in docker it did.

TLDR: I changed the extensions/api/script.py and added a time.sleep(5) in between calls, fixed it for me.

    blocking_api.start_server(BLOCKING_PORT, share=shared.args.public_api)
    time.sleep(5)
    streaming_api.start_server(STREAMING_PORT, share=shared.args.public_api)

juliankolbe avatar May 17 '23 07:05 juliankolbe

I've tried adding time.sleep and installing the flask cloudflared fix with no success :(

dje3392 avatar May 23 '23 22:05 dje3392

for some users, you simply have to give execute permissions to /tmp/cloudflared-linux-amd64

like this chmod +x /tmp/cloudflared-linux-amd64

This should be clear from the logs

PermissionError: [Errno 13] Permission denied: '/tmp/cloudflared-linux-amd64'

but that's easy to miss when you are also facing other errors. In my case I didn't have cloudflared installed on my os (Installing it on conda won't work, it has to be on the os) and I got the permission denied error, so when I installed it and the logs looked different I did not think of checking that file again, I assumed installing cloudflare would fix it and moved on to the next error I was facing. edit: also, make sure you have flask-cloudflared installed before trying anything suggested on this issue. pip install flask-cloudflared. Don't expect it to be on requirements.txt because it's not required.

pato-pan avatar Jun 23 '23 19:06 pato-pan

Still doesnt work for me, any updates?

ChenMorSays avatar Aug 09 '23 13:08 ChenMorSays

The real issue why this bug is happening is that both the blocking api and then streaming api start the _run_cloudflared more or less at the same time, and if this file '/tmp/cloudflared-linux-amd64' is not downloaded and ready fast enough, they collide as the file is still downloading. This is only a working theory, but on my host machine it had no problem, but as soon as this was running in docker it did.

TLDR: I changed the extensions/api/script.py and added a time.sleep(5) in between calls, fixed it for me.

    blocking_api.start_server(BLOCKING_PORT, share=shared.args.public_api)
    time.sleep(5)
    streaming_api.start_server(STREAMING_PORT, share=shared.args.public_api)

This hypothesis might be correct because sometimes it would run for me and sometimes it would crash. But adding in the 5 second sleep fixed the issue for me

adityasingh8010 avatar Aug 29 '23 23:08 adityasingh8010

I managed to run the API on one colab notebook and use it in another colab notebook using these steps

In first colab notebook Clone text-generation-webui and install all requirements

!pip install flask-cloudflared
%cd /content/text-generation-webui
!python3.10 server.py --loader ExLlama --model /content/text-generation-webui/models/Llama-2-13b-Chat-GPTQ --public-api

this will return a url something like this Starting non-streaming server at public url https://ABC-flag.trycloudflare.com/api

In second colab notebook Go to api-examples/api-example.py replace the above url in place of HOST

HOST = 'ABC-flag.trycloudflare.com'
URI = f'https://{HOST}/api/v1/generate'

Then run the file !python3.10 api-example.py

kushshrivastava avatar Oct 09 '23 08:10 kushshrivastava

This issue has been closed due to inactivity for 6 weeks. If you believe it is still relevant, please leave a comment below. You can tag a developer in your comment.

github-actions[bot] avatar Nov 20 '23 23:11 github-actions[bot]