Repository navigation
feat(relay): start-first update path with health-gated cutover and rollback - #77
Merged
Merged
Conversation
…llback The relay now drains on SIGTERM: it stops accepting, /health turns to 503 "draining", and it exits once its open connections end or the drain timeout passes. It can serve on a listening socket inherited from systemd, accepting on a dedicated thread because systemd flips an inherited socket to blocking mode each time it starts an instance. Two systemd slots share one socket unit, so the new version starts beside the old one on the same port without a proxy. cascade-relay-update.sh starts the idle slot, health-gates it, then stops the old slot so it drains. A new slot that exits, never becomes healthy or dies during the settle period is stopped and the old slot keeps serving. A test under test/relay-update drives the shipped units with systemctl --user: a clean update, the new slot killed mid-update, and a binary that cannot start, each with a probe on the shared port. CI runs it in a relay-update job.
…nt simulator The accept timeout is built with TimeValLike::microseconds so it compiles where time_t and suseconds_t are narrower than i64 (macOS). The inherited-listener path and its types are gated to Unix, so Windows builds carry no dead code. A public doc comment no longer links to a private item. The iOS logic tests target iPhone 17: the runner image no longer provides an iPhone 16 simulator.
Mearman
marked this pull request as ready for review
November 16, 2026 12:31
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.
The relay had no side-by-side update: replacing it refused connections while the new process started and ended every open session.
This adds a systemd socket handoff. Two slots (
blue,green) accept on one systemd-owned socket, so the new version starts beside the old one on the same port with no proxy.cascade-relay-update.sh NEW_BINARYstarts the idle slot, waits for/healthto return 200 and stay healthy, then stops the old slot, which drains its open sessions. If the new slot exits, never becomes healthy or dies in the settle window, it is stopped and the old slot keeps serving (exit status 1).Relay changes: SIGTERM drains (
/healthreturns 503draining, newconnections_openanddrainingmetrics,--drain-timeout-seconds), andlistenfdsupport for the inherited socket. systemd flips an inherited socket to blocking mode on every instance start, which broke the first version (the old slot's accept hung after a failed start), so accepting on an inherited socket runs on a thread with a 100 ms accept timeout.SO_REUSEPORT was rejected because closing a listener resets its queued connections. Docker
start-firstdoes not apply: a published port can be bound by one container, anddocker composeignores the setting. The docs say so and give thestop_grace_periodand proxy options for Docker.test/relay-update/test_update.pyruns the shipped units undersystemctl --userwith a probe on the shared port: a clean update, the new slot SIGKILLed mid-update, and a binary that cannot start. It passes on a Linux host; the newrelay-updateCI job is unverified until this PR's checks run, as it needs a user systemd manager on the runner.