-
Notifications
You must be signed in to change notification settings - Fork 7.3k
[Serve] Fix replicas hanging forever when requests are stuck draining… #60788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2311,38 +2311,23 @@ async def call_asgi(): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise asyncio.CancelledError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def perform_graceful_shutdown(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not RAY_SERVE_ENABLE_DIRECT_INGRESS or not self._ingress: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # if direct ingress is not enabled or the replica is not an ingress replica, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # we can just call the super method to perform the graceful shutdown. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await super().perform_graceful_shutdown() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # set the shutting down flag to True to signal ALBs with failing health checks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # to stop sending traffic to this replica. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self._shutting_down = True | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # If the replica was never initialized it never served traffic, so we | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # can skip the wait period. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if self._user_callable_initialized: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # in order to gracefully shutdown the replica, we need to wait for the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # requests to drain and for PROXY_MIN_DRAINING_PERIOD_S to pass. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # this is necessary because we want to give ALB time to update its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # target group to remove the replica from it and to mark this replica | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # as unhealthy. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # TODO(abrar): the code below assumes that once ALB marks a replica target | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # as unhealthy, it will not send traffic to it. This is not true because | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # ALB can send traffic to a replica if all targets are unhealthy. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # The correct way to handle is this we start the cooldown period since | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # the last request finished and wait for the cooldown period to pass. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RAY_SERVE_ENABLE_DIRECT_INGRESS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| and self._ingress | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| and self._user_callable_initialized | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # In direct ingress mode, we need to wait at least | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # RAY_SERVE_DIRECT_INGRESS_MIN_DRAINING_PERIOD_S to give external load | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # balancers (e.g., ALB) time to deregister the replica, in addition to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # waiting for requests to drain. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await asyncio.gather( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| asyncio.sleep(RAY_SERVE_DIRECT_INGRESS_MIN_DRAINING_PERIOD_S), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self._drain_ongoing_requests(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.info( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f"Replica {self._replica_id} successfully drained ongoing requests." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| super().perform_graceful_shutdown(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await super().perform_graceful_shutdown() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+2314
to
+2328
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The call to
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await self.shutdown() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Cancel direct ingress HTTP/gRPC server tasks if they exist. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if self._direct_ingress_http_server_task: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self._direct_ingress_http_server_task.cancel() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if self._direct_ingress_grpc_server_task: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Repeated log messages when replica shutdown times out
Low Severity
The removal of
_logged_shutdown_messagetracking causes the "did not shut down after grace period, force-killing it" log message to be printed repeatedly. Whencheck_stopped()is called in the control loop and the timeout has passed, it logs and callsforce_stop()every iteration until the actor fully terminates. The old code used_logged_shutdown_messageto ensure the message was only logged once. This can cause significant log spam during shutdown of stuck replicas.