Skip to content

(refactor) Pick First LB state machine - #2784

Open
nathanielford wants to merge 6 commits into
grpc:masterfrom
nathanielford:refactor/pick-first-state-machine
Open

(refactor) Pick First LB state machine#2784
nathanielford wants to merge 6 commits into
grpc:masterfrom
nathanielford:refactor/pick-first-state-machine

Conversation

@nathanielford

Copy link
Copy Markdown
Contributor

Motivation

The initial implementation of the PickFirst LB was a little tangled in how it implemented the Happy Eyeballs requirements. This meant it was handling some phases with special state and others without. Overall it made it hard to reason about.

Further, there was abehavior gaps between the original implementation and the spec: the original discards unselected addresses upon entering READY, causing subsequent reconnections from IDLE to only attempt the single failed address instead of sweeping all resolved backends.

Solution

This implementation is fairly different, using a state machine to hold state for each of the four states of Happy Eyeballs (Idle, FirstPass, SteadyState and Ready), and being clear about state transitions between them. The construction ensures the retention of appropriate information (i.e. addresses), and makes things easier to reason about.

As a bonus, this pass also eliminates a bunch of allocations that were unneeded. Gemini estimates about a 70% smaller memory footprint. As a double plus bonus, it now passes linting checks.

@nathanielford
nathanielford requested a review from arjan-bal July 30, 2026 22:33
@nathanielford
nathanielford marked this pull request as ready for review July 30, 2026 22:33
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.

1 participant