What is the purpose of cloudflared tunnel cleanup

I understand that cloudflared tunnel cleanup does this: “Delete connections for tunnels with the given UUIDs or names.”

What is the purpose of this command? Is it true if a cloudflared instance dies, connections it was using do not cleanup themselves, or is there some other reason this command exists?

In what other circumstances is it useful?

Hello @jon14

If cloudflared is closed gracefully (i.e. its shutdown completes normally) then connections will be closed with Cloudflare edge. In that case, cleanup would not be useful.

However, if the shutdown is not orderly, e.g. a kill -9 is issued, then connections in Cloudflare edge will only close after certain TCP timeouts take place. During that time, if you try to reconnect, or delete the tunnel, you may get an error saying that you need to force that in order to overwrite existing active connections — which is possible with “-f” flag. An alternative is to issue the cleanup command before doing either of that with “-f”.

All of this is true because a given tunnel can only be ran once. If you want to serve multiple origins as a single entity (e.g., replicas of the same service across various machines), you should run multiple tunnels and place them in the same Cloudflare Load Balancer origin: https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/routing-to-tunnel/lb

2 Likes