/config/ API returns old and new config randomly

1. The problem I’m having:

localhost:2019/config/API sometimes returns previous configuration with a different ETag.

2. Error messages and/or full log output:

curl -i localhost:2019/config/
HTTP/1.1 200 OK
Content-Type: application/json
Trailer: ETag
Date: Thu, 22 Feb 2024 04:49:38 GMT
Transfer-Encoding: chunked

{"apps":{"http":{"servers":{"serv0":{"listen":[":80",":443"],"routes":[{"handle":[{"handler":"reverse_proxy","upstreams":[{"dial":"http://localhost:3444"}]}],"match":[{"@id":"pages","host":["domain1.com"]}]}]}}}},"logging":{"logs":{"default":{"level":"DEBUG","writer":{"filename":"/var/log/caddy/caddy.log","output":"file"}}}}}
Etag: "/config/ d0602ed3"

curl -i localhost:2019/config/
HTTP/1.1 200 OK
Content-Type: application/json
Trailer: ETag
Date: Thu, 22 Feb 2024 04:49:42 GMT
Transfer-Encoding: chunked

{"apps":{"http":{"servers":{"serv0":{"listen":[":80",":443"],"routes":[{"handle":[{"handler":"reverse_proxy","upstreams":[{"dial":"http://localhost:3444"}]}],"match":[{"@id":"pages","host":["domain1.com","domain2.com"]}]}]}}}},"logging":{"logs":{"default":{"level":"DEBUG","writer":{"filename":"/var/log/caddy/caddy.log","output":"file"}}}}}
Etag: "/config/ 86e930bc"

Note that the request was made a few seconds apart and no changes were made at that time.

3. Caddy version:

v2.7.6

4. How I installed and ran Caddy:

Default Ubuntu package install

a. System environment:

Ubuntu 22.04

b. Command:

curl -i localhost:2019/config/

Caddy is running by the default service

c. Service/unit/compose file:

### Editing /etc/systemd/system/caddy.service.d/override.conf
### Anything between here and the comment below will become the contents of the drop-in file



### Edits below this comment will be discarded

### /lib/systemd/system/caddy.service
# # caddy.service
# #
# # For using Caddy with a config file.
# #
# # Make sure the ExecStart and ExecReload commands are correct
# # for your installation.
# #
# # See https://caddyserver.com/docs/install for instructions.
# #
# # WARNING: This service does not use the --resume flag, so if you
# # use the API to make changes, they will be overwritten by the
# # Caddyfile next time the service is restarted. If you intend to
# # use Caddy's API to configure it, add the --resume flag to the
# # `caddy run` command or use the caddy-api.service file instead.
#
# [Unit]
# Description=Caddy
# Documentation=https://caddyserver.com/docs/
# After=network.target network-online.target
# Requires=network-online.target
#
# [Service]
# Type=notify
# User=caddy
# Group=caddy
# ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
# ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile --force
# TimeoutStopSec=5s
# LimitNOFILE=1048576
# LimitNPROC=512
# PrivateTmp=true
# ProtectSystem=full
# AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
#
# [Install]
# WantedBy=multi-user.target

d. My complete Caddy config:

{"apps":{"http":{"servers":{"serv0":{"listen":[":80",":443"],"routes":[{"handle":[{"handler":"reverse_proxy","upstreams":[{"dial":"http://localhost:3444"}]}],"match":[{"@id":"pages","host":["domain1.com","domain2.com"]}]}]}}}},"logging":{"logs":{"default":{"level":"DEBUG","writer":{"filename":"/var/log/caddy/caddy.log","output":"file"}}}}}
Etag: "/config/ 86e930bc"

5. Links to relevant resources:

The concurrent configurations might be the issue but why does it hold the new and old configuration all the time and returns them via API randomly?

I don’t understand. Do you somehow have two Caddy processes running? It should be impossible for two to be bound to the same port though.

There’s definitely no way for Caddy to have two copies of a config.

Show your Caddy logs. Are you sure it’s not in some weird reload loop for some reason?

I think that was a good lead. I have disabled caddy process and left only caddy-api and I can’t reproduce the issue.

1 Like

Oh, you had both services active? Yeah that would make sense that it would cause that problem then. They were probably competing with eachother in a weird loop.

We have instructions for switching services here Keep Caddy Running — Caddy Documentation

1 Like

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