Configure Caddy to Hold Connection

1. Caddy version (caddy version):

TBD based on answers, but probably the latest and greatest.

2. How I run Caddy:

Probably by service using systems

a. System environment:

Will be a recent Linux, probably Ubuntu Server, so systemd and probably not using docker.

b. Command:

N/A

c. Service/unit/compose file:

N/A

d. My complete Caddyfile or JSON config:

N/A

3. The problem I’m having:

So I am evaluating using caddy as a reverse proxy to another HTTP application running in the background. For historical reasons there can only ever be a single instance of this application running. I want to get to as close as possible 0 downtime deployments for it.

The service restarts in a few seconds, but of course doing so drops all connections.

One idea suggested was to have the reverse proxy hold the incoming connections for 10 seconds before sending to the backend. Ideally by allowing the deployment to instruct the proxy to start doing this, wait a bit for current connections to drain, update the service and then instruct the proxy to go back to normal.

I had a look around and it seems Caddy might be a good candidate for this since it can be scripted against.

However no idea if this is even possible in Caddy and a look over the documentation didn’t really help there. Just looking to get some pointers (perhaps a link to the correct place in the documentation), and if it’s even possible.

4. Error messages and/or full log output:

N/A

5. What I already tried:

We have tried nothing man, and we’re all out of ideas!

6. Links to relevant resources:

N/A

In the proxy’s load balancing configuration, you want to set try_duration. If you set it to 10s with a try_interval of, say, 1s, Caddy will try to connect to the backend(s) every 1 second, for up to 10 seconds, before dropping the request.

1 Like

Cheers Matt. Sorry about pestering you on twitter about it. Should have come here initially.

That looks pretty close to perfect to me. Id have to modify that HTTP service to start denying connections I think but otherwise it looks like it should work.

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.