Skip to content

fix(gorouter): hash_balance as string (partial revert of #535) - #584

Closed
a18e wants to merge 3 commits into
cloudfoundry:developfrom
sap-contributions:fix-gorouter-hash-balance-as-string
Closed

a18e wants to merge 3 commits into
cloudfoundry:developfrom
sap-contributions:fix-gorouter-hash-balance-as-string

Conversation

@a18e

@a18e a18e commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR restores the original parsing of hash_balance.
The ,string suffix was removed as part of https://github.com/cloudfoundry/routing-release/pull/535/changes#diff-a3cb8cde907ca8ef9a573547cc9464f3bfa9348ce3beedcb838e768d40a99c85L46, which broke hash-based routing.

Backward Compatibility

Breaking Change? No, fixes (unintended?) breaking change.

See #585

Since v0.386.0, gorouter fails to unmarshal `router.register` NATS messages for any route configured with hash-based load balancing (`loadbalancing: hash`) that includes a `hash_balance` factor.
The message is rejected as a validation error and dropped, so the endpoint is never registered.
The route becomes unreachable (404 / stale until TTL expiry) even though the app and the registration message are healthy.

This restores the old parsing.
hoffmaen
hoffmaen previously approved these changes Sep 11, 2026
@github-project-automation github-project-automation Bot moved this from Inbox to Pending Merge | Prioritized in Application Runtime Platform Working Group Sep 11, 2026
@a18e
a18e marked this pull request as ready for review September 11, 2026 14:10
@a18e
a18e requested a review from a team as a code owner September 11, 2026 14:11
type RegistryMessageOpts struct {
LoadBalancingAlgorithm string `json:"loadbalancing"`
HashHeaderName string `json:"hash_header"`
HashBalance float64 `json:"hash_balance"`

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.

Could you please implement a new unit test in subscriber_test.go to ensure this regression is avoided during NATS message registration.

Something like:

It("parses hash_balance from the incoming JSON string", func() {
				data := []byte(`{"host":"host","app":"app","protocol":"http2","uris":["test.example.com"],"options":{"loadbalancing":"hash","hash_header":"X-Header","hash_balance":"1.5"}}`)

				err := natsClient.Publish("router.register", data)
				Expect(err).ToNot(HaveOccurred())

				Eventually(registry.RegisterCallCount).Should(Equal(1))
				_, originalEndpoint := registry.RegisterArgsForCall(0)
				expectedEndpoint := route.NewEndpoint(&route.EndpointOpts{
					Host:                   "host",
					AppId:                  "app",
					Protocol:               "http2",
					LoadBalancingAlgorithm: "hash",
					HashHeaderName:         "X-Header",
					HashBalanceFactor:      1.5,
				})

				Expect(originalEndpoint).To(Equal(expectedEndpoint))
			})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

gorouter drops hash-based route registrations — hash_balance no longer parsed when sent as a JSON string (regression introduced in v0.386.0 / #535)

3 participants