Repository navigation
fix: skip Caddy writes when a deploy leaves the route unchanged - #129
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Every Caddy admin API write is a full config reload, and on reload Caddy closes every proxied websocket with code 1001.
postRoute()always ranDELETE /id/<route>+POST routeson 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
postRoutefirst doescurl -sf GET /id/<route>. If Caddy already holds a route equal to the one Dockify would post, it logsCaddy route unchanged: <domain>and writes nothing. Otherwise (different target, auth added/removed/changed, or 404) the previous DELETE + POST sequence runs unchanged.anyand compared withreflect.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".authRoutenow reuses the hash from Caddy's current route whenbcrypt.CompareHashAndPasswordaccepts 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(fakessh.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.caddy:2container: 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