feat: start healthy and retry when Plex is unreachable at boot#302
Merged
Conversation
The initial Plex connect + admin resolution previously exited non-zero on any failure, so a Plex that was down at boot crash-looped the container under the restart policy. Now the startup classifies the failure: a fatal misconfiguration (bad token / 4xx, wrong-server 404, or a TLS/cert error) still exits non-zero, but a transient failure (Plex unreachable, DNS/timeout, or 5xx) marks the container healthy-degraded and retries the initial connect with capped exponential backoff (1s->30s) until Plex answers. This mirrors plex-exporter's fatal-vs-transient split and makes the container survive a Plex restart instead of crash-looping. Adds a typed plex.HTTPStatusError (carrying the status code, message unchanged) so the classifier can tell 4xx from 5xx, and a table test for the classifier + backoff.
Now that a transient connect failure starts the container healthy-degraded (previous commit), plex-language-sync can reach healthy in CI against an unreachable dummy Plex. Enroll it on the shared harness: tests/image-smoke.conf (env-only, PLEX_URL=http://127.0.0.1:1 + a dummy token) + the canonical tests/image-smoke.sh synced from cplieger/ci. Removes plex-language-sync's documented smoke-test exception.
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.
Summary
Makes plex-language-sync survive a Plex that is down at boot instead of crash-looping, and enrolls it on the shared image-smoke harness.
Previously the initial Plex connect + admin resolution exited non-zero on any failure, so under
restart: unless-stoppeda Plex outage at startup crash-looped the container. Startup now classifies the failure (mirroring plex-exporter):PLEX_TOKEN/4xx, wrong-server 404, TLS/cert error) -> exit non-zero; the container never goes healthy, so the misconfiguration stays loud.WebSocket disconnects after the initial connect are unchanged (the listener already reconnects with backoff).
Changes
internal/plex/client.go: add a typedHTTPStatusError(carries the status code; message text unchanged) so the classifier can distinguish 4xx from 5xx.main.go:connectAndResolveAdminretry-until-connected loop +isFatalStartupErrorclassifier + capped backoff;DeriveKeymoved ahead of the connect so a bad token is surfaced before any healthy-degraded marking.main_test.go: table test for the classifier + backoff.Smoke test
Enrolls plex-language-sync on the shared
configs/image-smoke.shharness (tests/image-smoke.conf, env-only dummyPLEX_URL/token). Validated locally: the image builds and the harness reportshealthy after 5sagainst an unreachable Plex. Removes plex-language-sync's documented smoke-test exception.Verification
go build,go vet,go test -race ./..., andgolangci-lint run/fmt --diffall clean.