oobabooga/textgen · error · Exception
Could not start cloudflared.
Error message
Could not start cloudflared.
What it means
Raised by _start_cloudflared (modules/api/utils.py:53) after max_attempts (default 3) consecutive failures of _run_cloudflared — the cloudflared binary ran but could not establish a tunnel (no route to Cloudflare edge, invalid/already-bound ports, tunnel_id rejected, missing binary). Each attempt's traceback is printed and the loop sleeps 3s before retrying.
Source
Thrown at modules/api/utils.py:53
raise Exception(
'flask_cloudflared not installed. Make sure you installed the requirements.txt for this extension.')
for _ in range(max_attempts):
try:
if tunnel_id is not None:
public_url = _run_cloudflared(port, port + 1, tunnel_id=tunnel_id)
else:
public_url = _run_cloudflared(port, port + 1)
if on_start:
on_start(public_url)
return
except Exception:
traceback.print_exc()
time.sleep(3)
raise Exception('Could not start cloudflared.')
View on GitHub (pinned to ed888c71f2)
Solutions
- Check the printed tracebacks of all 3 attempts — they distinguish network failure from binary/port issues.
- Ensure outbound TCP:7844 (and DNS) to Cloudflare is allowed; on restricted networks try cloudflared's --edge-ip-version or HTTP/2 fallback.
- Kill stale cloudflared processes (pkill cloudflared) so ports port/port+1 are free, then retry.
- If tunnels are systematically blocked, drop --public-api and expose via --listen + your own proxy.
Example fix
# before python server.py --api --public-api # retries 3x, then: Could not start cloudflared. # after pkill -f cloudflared python server.py --api --listen # LAN exposure without tunnel
Defensive patterns
Strategy: retry
Validate before calling
import socket, subprocess
def tunnel_prereqs_ok(port: int) -> bool:
# local ports free
for p in (port, port + 1):
with socket.socket() as s:
try:
s.bind(('0.0.0.0', p))
except OSError:
return False
return True
Try / catch
for attempt in range(3):
if start_server_with_public_api():
break
pkill_cloudflared()
time.sleep(3)
else:
fall_back_to_lan_listen() # run without --public-api
Prevention
- Kill orphaned cloudflared processes before each public-API start.
- Verify outbound connectivity to Cloudflare (tcp/7844) in firewalled environments.
- Treat public tunnels as best-effort: keep a --listen fallback path in your runbook.
When it happens
Trigger: Launching with --public-api (optionally --public-api-id) on a machine with no outbound connectivity to Cloudflare edge (port 7844 blocked), where cloudflared is not installed/downloadable, or the local metrics port (port+1) is already in use by a previous cloudflared instance.
Common situations: Firewalled/containerized environments blocking QUIC/TCP to Cloudflare; stale cloudflared process holding the tunnel or ports; offline machines; repeated starts leaving orphaned tunnel processes.
Related errors
- flask_cloudflared not installed. Make sure you installed the
- you MUST enable IPv6 or IPv4 for the API to work
- Access to non-public address {ip} is blocked
- Could not resolve hostname: {hostname}
- Too many redirects (max {max_redirects})
AI-assisted analysis of oobabooga/textgen@ed888c71f2 (2026-08-15).
Data as JSON: /api/errors/07a07c3b4701a71e.
Report an issue: GitHub.