1. Caddy version (caddy version
):
2.2.0
2. How I run Caddy:
a. System environment:
Docker
b. Command:
docker run -it -p 2019:2019 -p 80:80 --env-file .env mycaddy
c. Service/unit/compose file:
FROM caddy:2.2.0-builder AS builder
COPY ./caddy-proxyprotocol/ /usr/local/go/src/caddy-proxyprotocol
RUN xcaddy build \
--with caddy-proxyprotocol
FROM caddy:2.2.0
COPY --from=builder /usr/bin/caddy /usr/bin/caddy
COPY config/caddy.json /etc/caddy/caddy.json
CMD ["caddy", "run", "-config", "/etc/caddy/caddy.json"]
3. The problem I’m having:
I am facing issues with dynamic config updates using admin API’s.
For instance, I am triggering these two simultaneous requests:
- “method”: “PUT”, “host”: “localhost:2019”, “uri”: “/config/apps/http/servers/srv0/routes/0”
- “method”: “PATCH”, “host”: “localhost:2019”, “uri”: “/id/domain.com”,
Assume “@id” : “domain.com” is present at /config/apps/http/servers/srv0/routes/0
The issue is while making updates via API using @id mechanism, there is an internalRedir which implies that there is no global lock acquired for the whole operation. The path returned by the Config index for “id” provided might be no longer valid when the redirect request is served since the config could have been changed by some other request.
I guess the same is happening in my case as well.
4. What I already tried:
In my case I have to support “multiple domains and their subdomains” rules which can be edited dynamically at any times.
So structure for my config is like below with subdomain blocks structured inside parent blocks.
{
"@id": "sahil1.me",
"handle": [
{
"handler": "subroute",
"routes": [
{
"@id": "S_sahil1.me",
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "http_cache"
},
{
"handler": "reverse_proxy",
"upstreams": [
{
"dial": "13.127.152.23:80"
}
]
}
],
"match": [
{
"host": [
"sahil1.me"
]
}
],
"terminal": true
}
]
}
],
"match": [
{
"host": [
"*.sahil1.me",
"*.*.sahil1.me",
"*.*.*.sahil1.me",
"sahil1.me"
]
}
],
"terminal": true
}
]
}
],
"match": [
{
"host": [
"*.sahil1.me",
"*.*.sahil1.me",
"*.*.*.sahil1.me",
"sahil1.me"
]
}
],
"terminal": true
},
The above described issue leads to foreign subdomain block in a given parent domain block.
One way around is I just issue sequential updates by acquiring global lock because for now I acquire lock for a specific domain before issuing updates. But i don’t feel like doing that considering the number of requests i might receive.