Skip to content

Commit

Permalink
[Serve] fix flaky test_autoscaling_policy (ray-project#37527)
Browse files Browse the repository at this point in the history
Calling `.clear()` will free up the memory and can cause issue in raylet. Refactored `shutdown_cached_handles()` method for iterating through all cached handles and remove their reference to safely garbage collect the handles (which is what's done when calling `serve.shutdown()`).
  • Loading branch information
GeneDer authored and Bhav00 committed Jul 22, 2023
1 parent ac23214 commit b766284
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions python/ray/serve/_private/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,22 @@ def __del__(self):
def __reduce__(self):
raise RayServeException(("Ray Serve client cannot be serialized."))

def shutdown_cached_handles(self):
"""Shuts down all cached handles.
Remove the reference to the cached handles so that they can be
garbage collected.
"""
for cache_key in list(self.handle_cache):
del self.handle_cache[cache_key]

def shutdown(self, timeout_s: float = 30.0) -> None:
"""Completely shut down the connected Serve instance.
Shuts down all processes and deletes all state associated with the
instance.
"""

# Shut down handles
for k in list(self.handle_cache):
del self.handle_cache[k]
self.shutdown_cached_handles()

if ray.is_initialized() and not self._shutdown:
try:
Expand Down
2 changes: 1 addition & 1 deletion python/ray/serve/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def serve_instance(_shared_serve_instance):
# Clear all state between tests to avoid naming collisions.
_shared_serve_instance.delete_deployments(serve.list_deployments().keys())
# Clear the ServeHandle cache between tests to avoid them piling up.
_shared_serve_instance.handle_cache.clear()
_shared_serve_instance.shutdown_cached_handles()


def check_ray_stop():
Expand Down

0 comments on commit b766284

Please sign in to comment.