Skip to content

fix: skip Caddy writes when a deploy leaves the route unchanged - #129

Merged
coderbuzz merged 1 commit into
mainfrom
fix/caddy-skip-unchanged-route
Nov 17, 2026
Merged

coderbuzz merged 1 commit into
mainfrom
fix/caddy-skip-unchanged-route

Conversation

@coderbuzz

Copy link
Copy Markdown
Owner

Problem

Every Caddy admin API write is a full config reload, and on reload Caddy closes every proxied websocket with code 1001. postRoute() always ran DELETE /id/<route> + POST routes on each deploy, so deploying any app (e.g. an auto-deploy on push) disconnected the websocket clients of every app on the same server. Clients that never reconnect after 1001 (old Sockette-based signage players behind m-server) stay offline.

Fix

postRoute first does curl -sf GET /id/<route>. If Caddy already holds a route equal to the one Dockify would post, it logs Caddy route unchanged: <domain> and writes nothing. Otherwise (different target, auth added/removed/changed, or 404) the previous DELETE + POST sequence runs unchanged.

  • Comparison: both sides are decoded into any and compared with reflect.DeepEqual. Caddy echoes the route with keys sorted (and a trailing newline), so raw bytes never match; extra fields on Caddy's side make it "changed".
  • Basic auth: bcrypt salts differ per hash, so authRoute now reuses the hash from Caddy's current route when bcrypt.CompareHashAndPassword accepts the configured password for the same user. Unchanged user/password → equal route → no write. A new password or user → fresh hash → re-post. Cost: one bcrypt-14 compare (~1 s) per auth-route deploy.
  • SaveConfig() is still called: it only GETs /config/ and writes the file, which does not reload Caddy, and it heals a file left stale by an earlier failed save.

Tests

  • TestPostRouteSkipsUnchanged (fake ssh.Connector): unchanged plain route and unchanged auth route → no DELETE/POST; changed target, route missing (404), auth added, auth removed, new password → DELETE + POST [] + POST route as before.
  • Checked once by hand against a local caddy:2 container: Caddy's GET /id/ output for the plain and basic-auth shapes compares equal, and repeat deploys issued zero admin writes.
  • go build ./... && go vet ./... && go test ./... green.

🤖 Generated with Claude Code

Every Caddy admin API write is a config reload, and a reload closes every
proxied websocket on the server with code 1001. postRoute always did
DELETE + POST, so deploying any app disconnected the websocket clients of
every app on that server.

postRoute now GETs /id/<route> first and returns without writing when the
route Caddy holds equals the one Dockify would post (compared as decoded
JSON, since Caddy echoes keys sorted). For basic-auth routes the existing
bcrypt hash is reused when it still matches user and password, so an
unchanged auth route also compares equal; a new password still re-posts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderbuzz
coderbuzz merged commit 757a64f into main Nov 17, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant