Skip to content

[Serve] Fix HAProxy config file race condition and draining guard - #61120

Merged
abrarsheikh merged 2 commits into
ray-project:masterfrom
eicherseiji:fix-haproxy-config-race
Feb 18, 2026
Merged

abrarsheikh merged 2 commits into
ray-project:masterfrom
eicherseiji:fix-haproxy-config-race

Conversation

@eicherseiji

@eicherseiji eicherseiji commented Feb 17, 2026 •

Copy link
Copy Markdown
Contributor

Why are these changes needed

Summary

  • Fix config file write race: use a separate .lock file so the config isn't truncated before the lock is acquired. The previous open("w") + fcntl.flock() pattern allowed concurrent HAProxyManagers (in multi-node test environments on a single machine) to corrupt each other's config output.
  • Add draining guard in serving(): return early if the proxy is draining instead of looping forever waiting for backends to become healthy.
  • Remove leftover debug print statements from test files.

Test plan

  • test_drain_and_undrain_haproxy_manager passes 5/5 locally (previously failed ~2-3/5)
  • CI green on test_haproxy, test_metrics_haproxy, test_proxy

Fix two bugs in HAProxy test environments:

1. Use a separate lock file for config writes. The previous pattern
   opened the config file with "w" mode (which truncates) before
   acquiring fcntl.flock(), allowing concurrent writers to corrupt
   each other's output.

2. Add a draining guard in serving() so that a draining proxy
   returns immediately instead of looping forever waiting for
   backends to become healthy.

Also remove leftover debug print statements from test files.

Signed-off-by: Seiji Eicher <[email protected]>

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces several important fixes and cleanups for Ray Serve's HAProxy integration. The primary change addresses a race condition during HAProxy configuration file writes by using a separate .lock file. This prevents file truncation issues in concurrent environments. Additionally, a draining guard has been added to the serving() method to avoid infinite loops when a proxy is draining. Finally, some leftover debug print statements have been removed from test files, improving code cleanliness. The changes are well-implemented and address the issues described. The code quality is high, and the fixes are crucial for stability, especially in multi-node testing scenarios.

@eicherseiji eicherseiji added the go add ONLY when ready to merge, run all tests label Feb 17, 2026
@eicherseiji
eicherseiji marked this pull request as ready for review February 18, 2026 00:33
@eicherseiji
eicherseiji requested a review from a team as a code owner February 18, 2026 00:33
@eicherseiji

eicherseiji commented Feb 18, 2026 •

Copy link
Copy Markdown
Contributor Author
Screenshot 2026-02-17 at 6 15 19 PM

Passes premerge immediately

@harshit-anyscale

Copy link
Copy Markdown
Contributor

good find!

@abrarsheikh
abrarsheikh merged commit 95049c5 into ray-project:master Feb 18, 2026
3 checks passed
ans9868 pushed a commit to ans9868/ray that referenced this pull request Feb 18, 2026
…y-project#61120)

## Why are these changes needed
- `test_haproxy` flakiness:
https://buildkite.com/ray-project/postmerge/builds/16082#019c6c94-633e-4557-84e1-8a3e0ffd36ba

## Summary
- Fix config file write race: use a separate `.lock` file so the config
isn't truncated before the lock is acquired. The previous `open("w")` +
`fcntl.flock()` pattern allowed concurrent HAProxyManagers (in
multi-node test environments on a single machine) to corrupt each
other's config output.
- Add draining guard in `serving()`: return early if the proxy is
draining instead of looping forever waiting for backends to become
healthy.
- Remove leftover debug print statements from test files.

## Test plan
- [x] `test_drain_and_undrain_haproxy_manager` passes 5/5 locally
(previously failed ~2-3/5)
- [x] CI green on `test_haproxy`, `test_metrics_haproxy`, `test_proxy`

---------

Signed-off-by: Seiji Eicher <[email protected]>
Signed-off-by: Adel Nour <[email protected]>
Aydin-ab pushed a commit to kunling-anyscale/ray that referenced this pull request Feb 20, 2026
…y-project#61120)

## Why are these changes needed
- `test_haproxy` flakiness:
https://buildkite.com/ray-project/postmerge/builds/16082#019c6c94-633e-4557-84e1-8a3e0ffd36ba

## Summary
- Fix config file write race: use a separate `.lock` file so the config
isn't truncated before the lock is acquired. The previous `open("w")` +
`fcntl.flock()` pattern allowed concurrent HAProxyManagers (in
multi-node test environments on a single machine) to corrupt each
other's config output.
- Add draining guard in `serving()`: return early if the proxy is
draining instead of looping forever waiting for backends to become
healthy.
- Remove leftover debug print statements from test files.

## Test plan
- [x] `test_drain_and_undrain_haproxy_manager` passes 5/5 locally
(previously failed ~2-3/5)
- [x] CI green on `test_haproxy`, `test_metrics_haproxy`, `test_proxy`

---------

Signed-off-by: Seiji Eicher <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claude-code-assisted go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants