Skip to content

Grpc-Tunnel: Fix pool var rotation - #134

Merged
shawnburke merged 1 commit into
mainfrom
grpc/pool-rotation
Aug 28, 2026
Merged

Grpc-Tunnel: Fix pool var rotation#134
shawnburke merged 1 commit into
mainfrom
grpc/pool-rotation

Conversation

@shawnburke

Copy link
Copy Markdown
Collaborator

Stack 2/3 — base #133. Review the two-commit range or just the top commit.

The bug

Every request against a pooled origin failed.

Origin() runs os.ExpandEnv on the raw origin before the pool is consulted. A variable that exists only as VAR_POOL — which is the whole point of a pool — has no plain VAR in the environment, so ${API} expanded to the empty string. ResolvePoolVars then had nothing left to rotate: the ${API} reference it matches on was already gone.

Two things kept this hidden:

  • pool_test.go exercises PoolManager directly, so it never went through Origin() and stayed green.
  • varIsSet accepts VAR_POOL as satisfying a required variable, so an accept file declaring a pool loaded cleanly and only failed at request time.

The fix

The Router resolves from RawOrigin() — the origin exactly as written, ${VAR} intact — so ResolvePoolVars has a reference to rotate on. defaultScheme comes out of Origin() so both paths fill in https identically; Origin() now delegates to it and is otherwise unchanged.

Origin() is the one accessor this package shares with the snyk-broker reflector (relay_instance_manager.go). TestOriginContract pins its behaviour and is untouched by this change.

Test plan

  • router_pool_test.go covers rotation at the Router level, where the bug was — round-robin across requests, whitespace/empty-entry trimming, and a pool of one.
  • Verified these tests fail against the old resolution: reverting just the resolveOrigin call makes all three fail with a routing error, and restoring it makes them pass. The tests catch the regression rather than merely describing the fix.
  • go test ./server/snykbroker/... ./common/... green.

🤖 Generated with Claude Code

@shawnburke shawnburke changed the title Make origin pools rotate again Grpc-Tunnel: Fix pool var rotation Aug 28, 2026
aszarama
aszarama previously approved these changes Aug 28, 2026
Base automatically changed from grpc/auth-header-parity to main August 28, 2026 06:33
@shawnburke
shawnburke dismissed aszarama’s stale review August 28, 2026 06:33

The merge-base changed after approval.

`Origin()` expanded ${VAR} against the environment before the pool was
consulted, so a variable that exists only as `VAR_POOL` became the empty
string and every request against a pooled origin failed — while
`pool_test.go`, which exercises `PoolManager` directly, stayed green.

The Router now resolves the origin from `RawOrigin()`, with the ${VAR}
reference intact, so `ResolvePoolVars` has something left to rotate.
`defaultScheme` comes out of `Origin()` so both paths fill in https the
same way.

`router_pool_test.go` covers this at the Router level, where the bug
was; it fails against the old resolution.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@shawnburke
shawnburke requested a review from aszarama August 28, 2026 06:58
@shawnburke
shawnburke merged commit f3c2d37 into main Aug 28, 2026
20 checks passed
@shawnburke
shawnburke deleted the grpc/pool-rotation branch August 28, 2026 10:42
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.

2 participants