Thanks to visit codestin.com
Credit goes to github.com

Skip to content

caddyhttp: wait for servers from previous configs on exit - #8009

Open
dunglas wants to merge 1 commit into
caddyserver:masterfrom
dunglas:fix/wait-for-reloaded-servers
Open

caddyhttp: wait for servers from previous configs on exit#8009
dunglas wants to merge 1 commit into
caddyserver:masterfrom
dunglas:fix/wait-for-reloaded-servers

Conversation

@dunglas

@dunglas dunglas commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

After a configuration reload, a long-lived response can remain on an older HTTP server. A subsequent process termination waits only for the current HTTP app's servers, so Caddy can exit in the middle of that older response. This surfaced with Mercure SSE connections while reviewing dunglas/mercure#1365 and also reproduces without that change.

Track pending server shutdowns across HTTP app instances and wait for them during termination, bounded by the terminating configuration's grace period. Reloads still return without waiting for active responses. Keep each reloaded app's grace-period context alive until its shutdown finishes, instead of cancelling it as soon as the nonblocking stop returns.

Assistance Disclosure

Codex assisted with diagnosis, implementation, and regression tests. The checks and integration reproduction below were run against the resulting code.

Validation

  • Added HTTP/1.1 and HTTP/2 regression tests with both unlimited and finite reload grace periods, plus a check that termination's grace period bounds the wait. All four response-completion cases fail before the fix and pass afterward; repeated race runs pass.
  • Ran go test -race -short ./..., go build ./..., golangci-lint run --timeout 10m, go mod tidy -diff, and gopls checks on the changed files.
  • Rebuilt Mercure against this patch, opened 20 SSE connections, reloaded, then sent SIGTERM without opening connections on the new configuration. All 20 streams reached clean EOF across their write-deadline window. The unpatched Caddy ended all 20 with truncated responses immediately after SIGTERM.

Track pending HTTP server shutdowns across configuration reloads so
termination waits for responses still served by an older configuration.
Bound that wait by the terminating app's grace period and retain each
reload's grace context until its servers finish shutting down.

Cover HTTP/1.1, HTTP/2, and finite termination grace periods with
regression tests.
@dunglas
dunglas marked this pull request as ready for review September 10, 2026 12:28
@francislavoie
francislavoie requested a review from mholt September 10, 2026 16:05
@francislavoie francislavoie added the bug 🐞 Something isn't working label Sep 10, 2026
@francislavoie francislavoie added this to the v2.11.5 milestone Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🐞 Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants