Skip to content

Retry LLM proxy test binds that lose their port - #7329

Merged
ChrisJBurns merged 1 commit into
mainfrom
fix-llm-proxy-port-flake
Nov 26, 2026
Merged

ChrisJBurns merged 1 commit into
mainfrom
fix-llm-proxy-port-flake

Conversation

@ChrisJBurns

Copy link
Copy Markdown
Collaborator

Summary

The LLM proxy tests pick a port with freePort, which binds 127.0.0.1:0, closes the listener and returns the port number. New then binds that port. Another test running in parallel can take the port between those two steps. That failed TestHandler_Returns502OnTokenError in CI with bind: address already in use (seen on #4844, where a re-run passed).

  • Add newProxyOnFreePort. It builds the config on a fresh port, retries on another port (up to 5 attempts) when New fails with EADDRINUSE, and closes the listener on test cleanup.
  • Use it for every test that needs New to succeed. Tests that expect New to fail before binding still call New directly.
  • Remove the per-test listener closes, which the helper now handles.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe): Test-only fix for a flaky test

Test plan

  • Unit tests (task test)
  • E2E tests (task test-e2e)
  • Linting (task lint-fix)
  • Manual testing (describe below)

Linting is left to CI because the local golangci-lint crashes on the Go 1.27 toolchain.

Special notes for reviewers

This only changes test code; New is unchanged. The alternative is to let New accept an already-bound listener, which removes the race entirely but adds a constructor option used only by tests. Retrying keeps production code untouched. On Windows the bind error doesn't match syscall.EADDRINUSE, so a collision there still fails as before.

🤖 Generated with Claude Code

The LLM proxy tests pick a port by binding and closing it, then New
binds it again. A parallel test can take the port in between, which
failed TestHandler_Returns502OnTokenError in CI with 'address already
in use'. Create proxies through a helper that retries on another port
when the bind finds the port taken.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@github-actions github-actions Bot added the size/XS Extra small PR: < 100 lines changed label Nov 26, 2026
@codecov

codecov Bot commented Nov 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.25%. Comparing base (c038d02) to head (aeaa887).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7329      +/-   ##
==========================================
- Coverage   82.27%   82.25%   -0.02%     
==========================================
  Files         935      935              
  Lines       95159    95285     +126     
==========================================
+ Hits        78288    78381      +93     
- Misses      16866    16899      +33     
  Partials        5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ChrisJBurns
ChrisJBurns merged commit 317b713 into main Nov 26, 2026
47 checks passed
@ChrisJBurns
ChrisJBurns deleted the fix-llm-proxy-port-flake branch November 26, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS Extra small PR: < 100 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants