Skip to content

fix: Balance Spread endpoint traffic and keep TCP connections in place - #1223

Merged
privateip merged 4 commits into
mainfrom
fix/issue-1097
Nov 3, 2026
Merged

privateip merged 4 commits into
mainfrom
fix/issue-1097

Conversation

@privateip

@privateip privateip commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A Spread endpoint sent every consumer that had no local producer to the same remote producer, and a TCP connection that lost its flow pin could reset when the set of producers on its node had changed.

A pin-less connection now stays with the producer that already carries it. Remote consumers can spread across the eligible producers by rendezvous hashing, so a producer joining, leaving or turning Unhealthy moves only the consumers and connections it gains or loses.

The remote pairing is chosen by the consumer's node and also by the producer's node, so changing it must not refuse traffic while routers disagree:

  • A producer's node installs a producer half for the producer each pairing picks (first-by-name and rendezvous), whatever its own setting.
  • The consumer's own pairing comes from the new galactic-router option --service-spread-pairing / GALACTIC_ROUTER_SERVICE_SPREAD_PAIRING. It defaults to first, the previous behavior.
  • Router intents are keyed by consumer and producer, so one consumer's two producer halves can coexist on a node. ProgrammingPlan counts every accepting producer's node.

Note

Rollout: upgrading galactic-router changes no pairing, so a rolling or partial upgrade refuses nothing. Set rendezvous only after every node runs this version, since an older router accepts only first. Flipping the setting node by node is safe once all nodes accept both pairings. A later release can make rendezvous the default and then drop first. Single endpoints are unaffected, and no map layout changes, so the CNI reloads without recreating pinned maps.

Test plan

  • Remote consumers spread across producers under rendezvous, and a join, a leave or an Unhealthy report moves only the consumers that producer gains or loses
  • Under first, every remote consumer goes to the first producer by name, as before
  • Each producer node, under either setting, installs halves for exactly the consumers that either pairing sends to it
  • Two producer halves of one consumer on one node coexist in the router's applied state
  • With pins evicted after a producer joins, every TCP connection keeps its producer, draining or not, while a new connection reusing a recent tuple goes to an eligible producer
  • With all flow state cleared, a connection moves only to a producer that joined or away from one that left
  • --service-spread-pairing defaults to first and rejects unknown values
  • task lint, task build, task test:unit and uncached task test:e2e pass locally
  • CI passes

Fixes #1097

@privateip privateip self-assigned this Oct 29, 2026
@privateip privateip changed the title fix: Spread Spread-endpoint traffic evenly and keep connections in place fix: Balance Spread endpoint traffic and keep TCP connections in place Oct 29, 2026
@privateip
privateip marked this pull request as ready for review October 29, 2026 11:38
@privateip
privateip requested a review from a team as a code owner October 29, 2026 11:38
@privateip
privateip enabled auto-merge October 29, 2026 11:38
@privateip

Copy link
Copy Markdown
Contributor Author

Review record for head 60edc50.

pr-conventions-reviewer: merge, with nits. The nits were applied in 60edc50 (a comment rewrap in usid.c plus PR body edits). It also noted that open draft #596 edits usid.c; no action taken, since #596 has not been updated since 2026-09-24.

pr-adversary: merge. It ran go test ./internal/serviceroute/ and read the tie-break ordering. It could not run the root kernel suite. Its one decision finding asked only to wait for Unit Tests (root) and Build to go green.

Human decision: on 2026-10-29 the author chose "Ready + auto-merge", after being shown that every required check on 60edc50 had passed (Build, Lint, Unit Tests, Unit Tests (root), E2E Tests). That resolves the decision finding.

Local runs by the session on 52f7fab: lint, build, unit, task test:unit-root and uncached task test:e2e passed. The one exception, TestResolveInterfaces_EnvOverride/OnlyWhitespaceIsError, also fails on unmodified main on hosts with an IPv6 default route, and CI does not hit it.

CI on 60edc50: all checks passed, including the root kernel suite.

Auto-merge is enabled with the merge method. The main ruleset requires one approving review including a code owner, so the PR still waits for human approval.

@polylane

polylane Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Caution

Hold this merge. Moderate impact.
Merging this changes a Spread endpoint's remote producer from first-by-name to rendezvous hashing, and the consumer's node and the producer's node compute that pairing separately. During the DaemonSet rollout the two disagree, so the producer a consumer now targets has no half installed for it and drops its traffic.

View the full analysis →

Why. Merging this changes how a Spread endpoint picks its remote producer, from first-by-name to rendezvous hashing, and the consumer's node and the producer's node each compute that pairing. While galactic-router rolls node by node the two disagree, so the remote consumers whose pairing changed are refused until both nodes run the new version.

flowchart LR
  A["galactic-router rolling update"] --> B["new node: rendezvous pairing"]
  A --> C["old node: first producer by name"]
  B --> D["consumer sends to producer X"]
  C --> E["producer X installs no half"]
  D --> F["requests refused until both nodes upgraded"]
  E --> F
Loading

Before merging: Install the consumer's producer half when either the old first-by-name rule or the new rendezvous rule selects the producer, ship that alone, and remove the old rule in a later release.

Evidence · 5 steps

Trigger: the galactic-router DaemonSet rollout that ships this change, while one node runs the new pairing rule and its peer still runs the old one (Not measurable from this workspace: no galactic-router telemetry is reachable (zero series for container.googleapis.com/container/cpu/usage_time in datum-cloud-prod; the DaemonSet exists in neither connected cluster; reads of namespace galactic-system are denied on the staging cluster). The condition itself fires for every consumer of a Spread + PreferNodeLocal endpoint whose node holds no producer: the new rule keeps the old producer for about 1/E of them, E being the eligible producer count.)

  1. The remote producer of a Spread endpoint changes from the first eligible producer by namespace and name to rendezvous hashing of the consumer's UID with each producer's UID. internal/serviceroute/planner.go:354-382 (selectProducers now calls rendezvousProducer, defined at planner.go:385); the removed loop returned the first producer whose health was eligible.
  2. The consumer's node and the producer's node each compute that pairing, and a node installs the consumer's producer half only when it selects that consumer itself. internal/serviceroute/planner.go:209 (if producer.Status.Node == localNode) guards the RouteIntentRemoteProducer append at planner.go:212.
  3. A node still on the old version selects the old producer, so the producer the consumer now targets installs no half for it and the flow is refused. internal/plumbing/ebpf/prog/usid.c:5395-5405 (LOCAL_SET branch counts DROP_REASON_SERVICE_ROUTE_DENIED); the pull request note declares the refusal.
  4. Production rolls the router node by node, so the mixed-version window lasts the whole rollout and a coordinated single rollout cannot remove it. datum-cloud/infra apps/galactic-system/edge/galactic-router.yaml — a Flux Kustomization that health-checks DaemonSet galactic-router in namespace galactic-system, rendered per site (us-east-1-alice, us-west-1-alice, us-central-1-alice); its header states DaemonSets roll RollingUpdate.
  5. Most affected consumers change producer, so the refused set is not a rare subset. rendezvousProducer scores every eligible producer (planner.go:385-397); the old rule always returned the first by name, so a consumer keeps its producer only about 1 in E times.

Traffic: No production read supports a rate. datum-cloud-prod returns zero series for container.googleapis.com/container/cpu/usage_time over the last hour, the galactic-router DaemonSet is absent from infrastructure-control-plane-prod (Resource not found) and from the staging cluster (read denied), and the GCP project carries no k8s_container logs. The score rests on the resulting code and on the pull request's own note, which states the refusal.

Also considered · 3 refuted
  • Refuted · The new reverse-row probe drops or resets service flows outside the Spread path · The probe, the TCP-flags load and the rendezvous placement all sit inside the LOCAL_SET branch at usid.c:5395, which only the multi-producer Spread path enters.
  • Refuted · Go and eBPF rendezvous hashing disagree, so the two nodes never converge · The two functions answer different questions over different sets: rendezvousProducer chooses the endpoint's remote producer among the endpoint's candidates, while service_rendezvous_score ranks the members of the local set that the consumer's own node installs.
  • Refuted · The datapath reload recreates the pinned flow maps and resets established connections · The diff changes only the comment inside the map declaration and adds no map, key or value field, so the map layout is unchanged and the pinned maps survive the reload.
Analysed against 2 cloud accounts and 1 repository
  • Cloud accounts: datum-cloud-prod, infrastructure-control-plane-staging
  • Repository: datum-cloud/galactic

Fix with Polylane View in Polylane Pause assessments

Polylane could not find the cloud resources this repository manages, so this review looked at the entire cloud account. Connect this repository to its resources and the next review will focus on exactly what this code deploys to.

Connect resources

Polylane analysed 60edc50 for production impact. You can ask follow-ups by mentioning @polylane in a comment.

Rate this review: 👍 helpful · 👎 not helpful · 😕 confusing

@ecv ecv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes.

The balancing and pin-less TCP fixes are right, but the rollout drops traffic. During the galactic-cni rolling upgrade (maxUnavailable: 1), about (N-1)/N of remote Spread consumers move from first-by-name to a hashed producer. The consumer's node and the producer's node compute that pairing separately, so the new producer has no half installed until both nodes are upgraded, and the consumer's traffic is dropped. The Polylane production impact check fails on the same trajectory. A paused or partial rollout leaves the drop in place.

  • For one release, have the producer node accept a remote Spread consumer under either the old first-by-name pairing or the new hashed one, or install both halves. A rolling upgrade then refuses nothing, and the hashed-only form can follow once every node runs it.
  • The rest checks out. usid.c changes no map definition, key or value struct, or pinned name, so the reload keeps pinned maps. Both nodes derive the pairing from the same inputs (FNV-1a over the UIDs plus mix64 over sorted producers), so once upgraded they can't disagree. The rendezvous moves only the consumers a joining or leaving producer gains or loses.
  • The unit tests cover the stated claims: a pin-less TCP connection stays put after a join, a leave moves only its own flows, and the planner spreads consumers and moves them on Unhealthy.

Follow-ups:

  • Add a metric of remote Spread consumers refused for a pairing mismatch, so an operator can tell a stalled rollout from a real fault.
  • Smoke-load the program on the oldest production kernel. The added 16-iteration unrolled loops raise verifier cost, and only the CI kernel has loaded them.

A Spread endpoint consumer with no producer on its node was sent to the first producer, by namespace and name, that was not reported Unhealthy. Every such consumer landed on that one producer, and all of them moved together when it flapped.

selectProducers now picks the remote producer by rendezvous hashing of the consumer's attachment UID with each producer's UID, or namespace/name for an attachment with no UID. It keeps the existing tiers: producers reported Healthy or Unknown or not reported, then producers whose report expired, then all producers. Each consumer goes to the highest-scoring producer in the first non-empty tier. Consumers spread across the remote producers, and a producer joining, leaving or turning Unhealthy changes the choice only for consumers whose top producer it is. ProgrammingPlan calls the same function, so the nodes it schedules match the intents Compile emits.

The consumer's node and the producer's node each compute the pairing. While routers run mixed versions, a remote Spread consumer whose pairing changed is refused until both nodes run this version. Single endpoints are unaffected.

TestCompileSpreadSpreadsConsumersAcrossRemoteProducers sends 64 consumers to 4 remote producers and checks that each producer takes some. It then adds a fifth producer, removes one and reports one Unhealthy, and checks that only the consumers gained or lost move. It also compiles on each producer's node and checks that the producer halves match the consumer node's choices. Without the fix, all 64 consumers go to producer-0. Two existing tests that expected the first producer by name now check the same properties without depending on which producer wins, including that a consumer with every report expired goes where it would with no reports.

Related to #1097
A LocalSet route keeps a TCP connection on its producer through a pin in service_flow_table. That table is an LRU holding a quarter of service_reverse_table's flows, and a pin also ends after 300 seconds idle. A packet with no live pin was placed by hash % eligible_count. When a producer joined or left after the connection opened, most pin-less connections mapped to a different producer and reset, even though the connection's own reverse row still named its producer.

service_select_producer now does three things in order:
- A TCP packet with no live pin checks each member of the set for the reverse row this flow's packets left: the reply tuple on that member's interface, in LOCAL mode, for this consumer interface and that member's token, used within the flow timeout. If one matches and the member's interface identity still matches its token, the connection keeps that producer, draining or not, and is pinned again. This uses the same rule as the pin. An opening SYN (SYN without ACK) skips the probe, so a client reusing a recent tuple cannot reach a draining producer.
- Only a flow with neither a pin nor a reverse row is placed by hash. The hash is now rendezvous over the eligible members' identity tokens, so a producer joining or leaving moves only the connections it gains or loses.
- UDP still picks at random, through the same rendezvous step with a random hash.

No map layout changes, so loading this datapath recreates no pinned map.

TestUsidServiceEgress_LocalSetKeepsTCPFlowsWithoutPins opens 64 connections across two producers, adds a third and evicts every pin. Each connection must keep its producer. Without the fix, port 44030 moved from producer 50 to producer 1. The test then clears all flow state, adds the third producer again, and checks that each connection either stays or moves to the new producer, then that removing that producer moves only its own connections. TestUsidServiceEgress_LocalSetReverseRowFallback checks that a pin-less connection keeps a draining producer, that an opening SYN on the same tuple goes to an eligible producer, and that a producer whose interface was replaced is skipped. Removing the SYN check or the identity check makes it fail.

Related to #1097
One line of the service_select_producer comment ran to 130 columns. This rewraps the paragraph to the width the rest of the file uses. The comment text and the code are unchanged.
The consumer's node and the producer's node each choose a Spread consumer's remote producer. Switching that choice from first-by-name to rendezvous hashing in one release refused every consumer whose pairing changed while routers ran mixed versions, for the whole rolling upgrade.

A producer's node now installs a producer half for the producer each pairing picks, whatever its own setting. The consumer's own pairing is chosen by the new --service-spread-pairing (GALACTIC_ROUTER_SERVICE_SPREAD_PAIRING) option, which defaults to first, the previous behavior. Once every node runs this router, setting rendezvous node by node refuses nothing, since every producer node already accepts both pairings. A later release can make rendezvous the default and then drop the first pairing.

Applied intents are now keyed by consumer and producer, so the two producer halves of one consumer can coexist on a node. ProgrammingPlan counts the nodes of every accepting producer.
@privateip

Copy link
Copy Markdown
Contributor Author

Addressed the rollout finding in 5b86f2f, rebased onto main.

Accept-both on the producer side alone covers only an old consumer facing an upgraded producer. An upgraded consumer facing an old producer would still be refused, because the old router installs only the first-by-name half. The fix has two parts:

  • Producer nodes accept both pairings. A producer's node installs a producer half for the producer that first-by-name picks and for the one rendezvous picks, whatever its own setting. Router intents are now keyed by (consumer, producer), so both halves of one consumer can coexist on a node, and ProgrammingPlan counts every accepting producer's node.
  • Consumers keep first-by-name until told otherwise. The new galactic-router option --service-spread-pairing / GALACTIC_ROUTER_SERVICE_SPREAD_PAIRING defaults to first. Upgrading therefore changes no consumer's producer, and a rolling or paused upgrade refuses nothing. Once every node runs this version, setting rendezvous (node by node is fine) is also drop-free, since every producer node already accepts both. A later release can make rendezvous the default and then drop first.

Tests: the spread test now checks that each producer node, under either setting, installs halves for exactly the consumers that either pairing sends to it. The fallback test runs under both pairings, and a controller test covers two producer halves of one consumer coexisting. Local task lint, task build, task test:unit and an uncached task test:e2e pass. I did not run task test:unit-root locally. CI's root suite covers the unchanged usid.c.

Follow-ups not in this PR:

  • A metric of remote Spread consumers refused for a pairing mismatch. With accept-both this should only fire if rendezvous is set before every node is upgraded, but it would still help tell a stalled rollout from a fault.
  • A smoke load of usid.c on the oldest production kernel to check verifier cost.

@privateip
privateip requested a review from ecv November 3, 2026 01:17

@ecv ecv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve.

The rollout drop is closed. Producer nodes now install a producer half for the producer each pairing picks, so an old consumer facing an upgraded producer is accepted, and consumers stay on first-by-name by default (--service-spread-pairing, default first), so an upgraded consumer facing an old producer is also unchanged. A rolling or paused upgrade therefore refuses nothing, which covers the case my either-pairing suggestion alone did not.

  • firstProducer matches main's old selection exactly: first eligible by order, then first expired, then producers[0]. So first changes no consumer's producer on upgrade.
  • Intents are keyed by IntentSlot (consumer, producer) so two producer halves of one consumer coexist. The programmer's grant and marker entries are keyed by the producer's own interface, so two halves on one node do not collide. ProgrammingPlan counts every accepting producer's node.
  • Flipping to rendezvous after every node runs this build is drop-free, node by node. The docs say to set it only then. They do not say to set it back to first before rolling any node back to an older router: after the flip, such a node refuses the rendezvous pairing. Add that sentence.
  • ci / Build and test fails internal/edge/masque TestAgainstCore/stale_delete_keeps_the_replacement (PrefixConflict), a package this diff does not touch. The CI workflow's unit, root-kernel and e2e jobs pass at the head; the failed job is re-running.

Follow-ups:

  • The mismatch metric is still not added. With accept-both it only fires if rendezvous is set too early or on a node rolled back, but it is how an operator would tell that from a fault.
  • The oldest-kernel verifier smoke load is still not done. usid.c keeps the 16-iteration unrolled loops, and only the CI kernel has loaded them. Do it before the default flips to rendezvous.
  • With the default at first, nothing is balanced until someone sets the option. Track the later release that makes rendezvous the default and drops first.

@privateip
privateip merged commit 45e1e0b into main Nov 3, 2026
27 of 28 checks passed
@privateip
privateip deleted the fix/issue-1097 branch November 3, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spread endpoints send every remote consumer to one producer

2 participants