Repository navigation
fix: Varnish VCL no longer crashes with multiple projects - #127
Closed
jakwinkler wants to merge 1 commit into
Closed
jakwinkler wants to merge 1 commit into
jakwinkler wants to merge 1 commit into
Conversation
The shared Varnish container generated one backend per registered project, but the template only ever referenced DefaultBackend. Varnish 7.x treats a defined-but-unused backend as a fatal compile error (Unused backend ...), so with 2+ projects the container failed to compile its VCL and crash-looped (502). The health probe also used HEAD / expecting 301 while Magento returns 302, marking the backend sick (503). Nginx already routes to the right project by Host header, so all per-project backends were identical. Emit a single 'magento' backend and probe GET /health_check.php expecting 200. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Contributor
Author
|
Superseded by the v2 PR — #127 patched only the unused lib template; the embedded template stayed broken. See the new PR. |
peterjaap
pushed a commit
that referenced
this pull request
Aug 10, 2026
buildVCLConfig emitted one backend per project but the template only referenced DefaultBackend, so Varnish 7.x aborted on the first unused backend and crash-looped (502). The probe also used HEAD / expecting 301 while Magento returns 302 (503). Emit a single 'magento' backend (Nginx routes per project by Host) and probe GET /health_check.php expecting 200. Fixes both the embedded template (internal/varnish/templates) and the lib copy. Supersedes #127 (which patched only the unused lib template). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
peterjaap
pushed a commit
that referenced
this pull request
Aug 10, 2026
buildVCLConfig emitted one backend per project but the template only referenced DefaultBackend, so Varnish 7.x aborted on the first unused backend and crash-looped (502). The probe also used HEAD / expecting 301 while Magento returns 302 (503). Emit a single 'magento' backend (Nginx routes per project by Host) and probe GET /health_check.php expecting 200. Fixes both the embedded template (internal/varnish/templates) and the lib copy. Supersedes #127 (which patched only the unused lib template). Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
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.
What's wrong
With two or more registered MageBox projects, the shared
magebox-varnishcontainer crash-loops and the storefront returns 502 / 503. Two bugs in VCL generation:1. Unused backends → fatal Varnish compile error
buildVCLConfig(internal/varnish/vcl.go) emitted onebackendper project, but the template (lib/templates/varnish/default.vcl.tmpl) only ever referencesDefaultBackend:The "Set backend based on Host header" loop emitted only comments. Varnish 7.x treats a defined-but-unused backend as a fatal compile error (
Unused backend <name>), so the VCL fails to compile and the container crash-loops → port 6081 dead → nginx 502.Every generated backend was identical (
host.docker.internal:8080) anyway, because Nginx already routes to the right project byHostheader — the per-project loop was pointless.2. Wrong health probe
The template hardcoded
HEAD /expecting.expected_response = 301, but Magento returns 302 onHEAD /→ backend markedsick→ 503. TheBackendConfig.ProbeURLfield (already/health_check.php) was ignored.Observed in the wild on a host with ~40 MageBox projects (40 backends in the VCL). Recurs on every
magebox start/ restart, overwriting any manual patch to~/.magebox/varnish/default.vcl.The fix
buildVCLConfignow emits exactly one backend namedmagento, regardless of project count. Nginx does the per-project routing.GET /health_check.phpexpecting200(usesProbeURL).sanitizeNamehelper + its test (only used for per-project backend names).rangeblock invcl_recv.Tests
TestVCLGenerator_GenerateMultipleProjectsrewritten as a regression test: asserts exactly one backend definition, presence ofbackend magento, absence of per-project backends, andset req.backend_hint = magento.TestVCLGenerator_Generatenow asserts the probe (GET /health_check.php+.expected_response = 200).buildVCLConfig/ empty-configs tests updated to expect the singlemagentobackend.go test ./...green (22 packages),golangci-lint run0 issues,go vetclean.Release
Bumps
VERSION→ 1.18.1 and adds aCHANGELOG.mdFixed entry. After merge, CI auto-tags from VERSION and ships the binaries (magebox self-update), so the fix survives restarts — no more manual VCL patching.🤖 Generated with Claude Code