Unable to reload in no time like Nginx does

Almost every time(very often), after ./caddy reload is executed, it just hang there, unless you hit CTRL+C, and sometimes it fails to reload. I don’t know the reason, and just want the instantaneous reload like Nginx.

I am using Caddy like this: vim Caddyfile. —> kill -9 caddy_pid; ----> ./caddy(start) —> test

~/caddy# vim Caddyfile
~/caddy# ./caddy reload
2022/02/09 09:06:37.374	INFO	using adjacent Caddyfile
2022/02/09 09:06:37.377	INFO	admin.api	received request	{"method": "POST", "host": "localhost:2019", "uri": "/load", "remote_addr": "127.0.0.1:48820", "headers": {"Accept-Encoding":["gzip"],"Content-Length":["3021"],"Content-Type":["application/json"],"Origin":["localhost:2019"],"User-Agent":["Go-http-client/1.1"]}}
2022/02/09 08:54:43.691	ERROR	admin	stopping current admin endpoint	{"error": "shutting down admin server: context deadline exceeded"}

When you run caddy reload, Caddy waits until the requests that used the original config to complete before returning a response to the command. If the reload is cancelled, then it’ll revert back to the original config.

So if you have requests that take a long time for example websocket connections or long-polling or large downloads, then it’ll never finish.

What you can do though is set the grace_period global option, which configures how long to wait for requests to complete before cancelling the requests so that the reload can complete. This may cause some requests to respond with errors since they were cancelled, but it will let the reload complete.

1 Like

Thank you Francis! After I upgraded to v2.4.6, it seems fine until now.

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