Skip to content

Commit

Permalink
[serve] Fix small bugs (ray-project#39778)
Browse files Browse the repository at this point in the history
Fix two bugs:
1. Application target state checkpoint is not deleted when Serve is shutdown, so you will see `Recovering target state for application 'default' from checkpoint` each time you start Serve again. It "recovers" the default target state so there is no actual difference, but this is still a bug and the confusing log is printed to console + log files.
<img width="1202" alt="Screen Shot 2023-09-20 at 3 35 19 PM" src="https://github.com/ray-project/ray/assets/15851518/85a63678-6c99-4e3c-a2fd-9b795b0e10dd">

2. Typo in `deploy_config`. We have a generic catch block in case unexpected errors are thrown, had a typo in that block (which is untested since it's for unexpected errors).
  • Loading branch information
zcin authored Sep 21, 2023
1 parent f984353 commit 0f383cb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
4 changes: 3 additions & 1 deletion python/ray/serve/_private/application_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def deploy_config(
except Exception:
self._set_target_state_deployment_infos(None)
self._update_status(
BuildAppStatus.FAILED,
ApplicationStatus.DEPLOY_FAILED,
(
f"Unexpected error occured while applying config for "
f"application '{self._name}': \n{traceback.format_exc()}"
Expand Down Expand Up @@ -846,6 +846,8 @@ def shutdown(self) -> None:
for app_state in self._application_states.values():
app_state.delete()

self._kv_store.delete(CHECKPOINT_KEY)

def is_ready_for_shutdown(self) -> bool:
"""Return whether all applications have shut down.
Expand Down
33 changes: 33 additions & 0 deletions python/ray/serve/tests/test_standalone_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,5 +379,38 @@ def __call__(self):
)


def test_checkpoint_deleted_on_serve_shutdown(start_and_shutdown_ray_cli_function):
"""Test the application target state checkpoint is deleted when Serve is shutdown"""

file1 = """from ray import serve
@serve.deployment
class A:
def __call__(self):
return "Hello A"
serve.run(A.bind())"""

file2 = """from ray import serve
@serve.deployment
class B:
def __call__(self):
return "Hello B"
serve.run(B.bind())"""

with NamedTemporaryFile() as f1, NamedTemporaryFile() as f2:
f1.write(file1.encode("utf-8"))
f1.seek(0)
output = subprocess.check_output(["python", f1.name], stderr=subprocess.STDOUT)
print(output.decode("utf-8"))
assert "Connecting to existing Ray cluster" in output.decode("utf-8")
subprocess.check_output(["serve", "shutdown", "-y"])

f2.write(file2.encode("utf-8"))
f2.seek(0)
output = subprocess.check_output(["python", f2.name], stderr=subprocess.STDOUT)
print(output.decode("utf-8"))
assert "Connecting to existing Ray cluster" in output.decode("utf-8")
assert "Recovering target state for application" not in output.decode("utf-8")


if __name__ == "__main__":
sys.exit(pytest.main(["-v", "-s", __file__]))

0 comments on commit 0f383cb

Please sign in to comment.