Skip to content

[Serve] Gate replica/deployment creation during shutdown - #62761

Merged
abrarsheikh merged 4 commits into
ray-project:masterfrom
vaishdho1:serve-shutdown-gate-new-replicas-clean
May 12, 2026
Merged

abrarsheikh merged 4 commits into
ray-project:masterfrom
vaishdho1:serve-shutdown-gate-new-replicas-clean

Conversation

@vaishdho1

@vaishdho1 vaishdho1 commented Apr 20, 2026 •

Copy link
Copy Markdown
Contributor

Description

During Serve shutdown, new deployments could still be created and replicas scaled up, leaking Ray actors. This PR adds _shutting_down early return guards on:

  • deploy(), autoscale(), set_target_num_replicas() in DeploymentStateManager
  • deploy_applications(), apply_config() in ServeController

Tests

  • test_shutdown_blocks_deploy — deploy is a no-op after shutdown, no replicas created
  • test_shutdown_blocks_autoscale — autoscale is a no-op, target stays at 0
  • test_shutdown_blocks_set_target_num_replicas — set_target_num_replicas is a no-op, no exception raised

Related issues

Fixes #62730

@vaishdho1
vaishdho1 requested a review from a team as a code owner April 20, 2026 04:24

@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 guards to prevent new deployments, configuration updates, and replica scaling while the Ray Serve controller is shutting down. Key changes include adding checks for the _shutting_down flag in the controller and deployment state manager, along with corresponding unit tests. Review feedback highlights that the _shutting_down flag must be explicitly set to True within the shutdown method for these guards to be effective and recommends adding warning logs when requests are ignored to improve observability.

Comment thread python/ray/serve/_private/controller.py Resolved
Comment thread python/ray/serve/_private/controller.py Resolved
@ray-gardener ray-gardener Bot added serve Ray Serve Related Issue community-contribution Contributed by the community labels Apr 20, 2026
@abrarsheikh abrarsheikh added the go add ONLY when ready to merge, run all tests label Apr 23, 2026
…te-new-replicas-clean

Signed-off-by: Vaishnavi Panchavati <[email protected]>
@vaishdho1
vaishdho1 force-pushed the serve-shutdown-gate-new-replicas-clean branch from 7c41ffe to 2d78251 Compare April 27, 2026 22:12
@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label May 12, 2026
@abrarsheikh
abrarsheikh merged commit 4a2a6d8 into ray-project:master May 12, 2026
3 checks passed
Lucas61000 pushed a commit to Lucas61000/ray that referenced this pull request May 15, 2026
…#62761)

## Description
During Serve shutdown, new deployments could still be created and
replicas scaled up, leaking Ray actors. This PR adds `_shutting_down`
early return guards on:

- deploy(), autoscale(), set_target_num_replicas() in
DeploymentStateManager
- deploy_applications(), apply_config() in ServeController

### Tests
- test_shutdown_blocks_deploy — deploy is a no-op after shutdown, no
replicas created
- test_shutdown_blocks_autoscale — autoscale is a no-op, target stays at
0
- test_shutdown_blocks_set_target_num_replicas — set_target_num_replicas
is a no-op, no exception raised
## Related issues
Fixes ray-project#62730

---------

Signed-off-by: Vaishnavi Panchavati <[email protected]>
alexandrplashchinsky pushed a commit to alexandrplashchinsky/ray-alex that referenced this pull request May 29, 2026
…#62761)

## Description
During Serve shutdown, new deployments could still be created and
replicas scaled up, leaking Ray actors. This PR adds `_shutting_down`
early return guards on:

- deploy(), autoscale(), set_target_num_replicas() in
DeploymentStateManager
- deploy_applications(), apply_config() in ServeController

### Tests
- test_shutdown_blocks_deploy — deploy is a no-op after shutdown, no
replicas created
- test_shutdown_blocks_autoscale — autoscale is a no-op, target stays at
0
- test_shutdown_blocks_set_target_num_replicas — set_target_num_replicas
is a no-op, no exception raised
## Related issues
Fixes ray-project#62730

---------

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

Labels

community-contribution Contributed by the community go add ONLY when ready to merge, run all tests serve Ray Serve Related Issue stale The issue is stale. It will be closed within 7 days unless there are further conversation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Serve] No hard gate prevents new replicas/deployments during shutdown; race can leak actors

2 participants