Skip to content

[Serve] Fix gang scheduling PG leak when deployment actors are starting#62469

Merged
abrarsheikh merged 5 commits into
ray-project:masterfrom
harshit-anyscale:deflake-test-deployment-actors-v2
Apr 11, 2026
Merged

[Serve] Fix gang scheduling PG leak when deployment actors are starting#62469
abrarsheikh merged 5 commits into
ray-project:masterfrom
harshit-anyscale:deflake-test-deployment-actors-v2

Conversation

@harshit-anyscale

@harshit-anyscale harshit-anyscale commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix a placement group leak in gang scheduling when deployment actors are configured.

Root cause

When a deployment uses both gang scheduling and deployment actors, _reserve_gang_placement_groups() creates placement groups every control loop tick (~100ms) while deployment actors are starting. But scale_deployment_replicas() defers replica creation until actors are ready, leaving the PGs orphaned. After ~2 seconds, all cluster resources are consumed by phantom PGs and replicas can never be scheduled — deadlock.

The sequence on every tick while deployment actors are starting:

  1. _reserve_gang_placement_groups(): replica delta > 0 → creates PG (reserves 2 CPUs)
  2. scale_deployment_replicas(): deployment actors not ready → returns empty upscale → PG unused
  3. Next tick: creates another PG (delta still > 0), still empty upscale
  4. After ~18 ticks (~2s): all 36 CPUs consumed by orphaned PGs, zero resources left

Fix

Skip PG reservation in _reserve_gang_placement_groups() when deployment actors are configured but not yet ready, matching the precondition already in scale_deployment_replicas().

🤖 Generated with Claude Code

@harshit-anyscale harshit-anyscale requested a review from a team as a code owner April 9, 2026 08:47
@harshit-anyscale harshit-anyscale added the go add ONLY when ready to merge, run all tests label Apr 9, 2026
@harshit-anyscale harshit-anyscale self-assigned this Apr 9, 2026

@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 a serve_instance fixture in test_deployment_actors.py to restart the Serve controller between tests, preventing performance degradation caused by accumulated state. Feedback suggests replacing delete_all_apps() with serve.shutdown() in the fixture teardown to more reliably ensure a clean state if the controller becomes unresponsive.

Comment thread python/ray/serve/tests/test_deployment_actors.py Outdated
@harshit-anyscale harshit-anyscale changed the title [Serve] Deflake test_deployment_actors: per-test Serve restart to prevent controller degradation Apr 9, 2026
@ray-gardener ray-gardener Bot added the serve Ray Serve Related Issue label Apr 9, 2026
@jeffreywang88

Copy link
Copy Markdown
Contributor

signing off for the gang scheduling pieces

Comment thread python/ray/serve/tests/test_deployment_actors.py Outdated
When a deployment uses both gang scheduling and deployment actors,
_reserve_gang_placement_groups() creates placement groups every control
loop tick (~100ms) while deployment actors are starting. But
scale_deployment_replicas() defers replica creation until actors are
ready, leaving the PGs orphaned. After ~2 seconds all cluster resources
are consumed by phantom PGs and replicas can never be scheduled.

Fix: skip PG reservation in _reserve_gang_placement_groups() when
deployment actors are configured but not yet ready, matching the
precondition in scale_deployment_replicas().

Before: test_gang_scheduling_with_deployment_actors hangs for 180s
After: passes in 34s

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: harshit <harshit@anyscale.com>
@harshit-anyscale harshit-anyscale force-pushed the deflake-test-deployment-actors-v2 branch from dc92046 to a184afa Compare April 9, 2026 16:43
@harshit-anyscale harshit-anyscale changed the title [Serve] Deflake test_deployment_actors: per-test Serve restart + fix gang scheduling PG leak Apr 9, 2026
@abrarsheikh abrarsheikh merged commit d8498f6 into ray-project:master Apr 11, 2026
6 checks passed
HLDKNotFound pushed a commit to chichic21039/ray that referenced this pull request Apr 22, 2026
…ng (ray-project#62469)

## Summary

Fix a placement group leak in gang scheduling when deployment actors are
configured.

### Root cause

When a deployment uses both gang scheduling and deployment actors,
`_reserve_gang_placement_groups()` creates placement groups every
control loop tick (~100ms) while deployment actors are starting. But
`scale_deployment_replicas()` defers replica creation until actors are
ready, leaving the PGs orphaned. After ~2 seconds, all cluster resources
are consumed by phantom PGs and replicas can never be scheduled —
deadlock.

**The sequence on every tick while deployment actors are starting:**
1. `_reserve_gang_placement_groups()`: replica delta > 0 → creates PG
(reserves 2 CPUs)
2. `scale_deployment_replicas()`: deployment actors not ready → returns
empty upscale → PG unused
3. Next tick: creates another PG (delta still > 0), still empty upscale
4. After ~18 ticks (~2s): all 36 CPUs consumed by orphaned PGs, zero
resources left

### Fix

Skip PG reservation in `_reserve_gang_placement_groups()` when
deployment actors are configured but not yet ready, matching the
precondition already in `scale_deployment_replicas()`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: harshit <harshit@anyscale.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Lucas61000 pushed a commit to Lucas61000/ray that referenced this pull request May 15, 2026
…ng (ray-project#62469)

## Summary

Fix a placement group leak in gang scheduling when deployment actors are
configured.

### Root cause

When a deployment uses both gang scheduling and deployment actors,
`_reserve_gang_placement_groups()` creates placement groups every
control loop tick (~100ms) while deployment actors are starting. But
`scale_deployment_replicas()` defers replica creation until actors are
ready, leaving the PGs orphaned. After ~2 seconds, all cluster resources
are consumed by phantom PGs and replicas can never be scheduled —
deadlock.

**The sequence on every tick while deployment actors are starting:**
1. `_reserve_gang_placement_groups()`: replica delta > 0 → creates PG
(reserves 2 CPUs)
2. `scale_deployment_replicas()`: deployment actors not ready → returns
empty upscale → PG unused
3. Next tick: creates another PG (delta still > 0), still empty upscale
4. After ~18 ticks (~2s): all 36 CPUs consumed by orphaned PGs, zero
resources left

### Fix

Skip PG reservation in `_reserve_gang_placement_groups()` when
deployment actors are configured but not yet ready, matching the
precondition already in `scale_deployment_replicas()`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: harshit <harshit@anyscale.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests serve Ray Serve Related Issue

3 participants