Repository navigation
[Jobs] Making sure JobManager retries JobSupervisor.ping before declaring job as failed - #47166
alexeykudinkin wants to merge 12 commits into
Conversation
Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
Added timeout handling Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
| else: | ||
| raise e |
There was a problem hiding this comment.
nit: wrap the exception with something saying it was retried X times or total duration
There was a problem hiding this comment.
Yeah, i see where you're coming from but am wary to wrap exceptions as that would mean that starting to use this util will mandate updating every try-catch block to accommodate for the same exceptions
|
|
||
| return async_call_with_retry( | ||
| _ping, | ||
| exception_classes=(ray.exceptions.RpcError, asyncio.TimeoutError), |
There was a problem hiding this comment.
I don't think this can/should ever raise an RpcError. It would raise a RayTaskError or RayActorError (and retries for those are handled by/configured in Ray)
There was a problem hiding this comment.
do we have a traceback showing that this codepath raised an RpcError?
There was a problem hiding this comment.
So we don't have the traceback unfortunately but this is what made me think that it was wrapped into RpcError
- "Deadline Exceeded" is typical gRPC client-side exception (timeout)
- We seem to wrap transport failures into RpcError here
There was a problem hiding this comment.
Oh, and also to clarify: i don't think the issue here is on the JobSupervisor end -- my hypothesis is that we're stalling the event-loop/GIL in the Agent itself therefore making it gRPC client timeout even before it's able to process response from the supervisor
There was a problem hiding this comment.
Oh, boy, i've just realized it couldn't happen for actor call b/c we never set timeout on those -- it's definitely one of the GCS RPCs
There was a problem hiding this comment.
This doesn't really make sense for actor calls. They will never raise RpcError because retries/grpc connection details are abstracted by the c++ layer
There was a problem hiding this comment.
I think it is indeed the GCS RPCs that we should be retrying not the actor calls
There was a problem hiding this comment.
e.g., stack trace that I saw:
2024-08-14 23:24:49 ray.exceptions.RpcError: Deadline Exceeded
2024-08-14 23:24:49 File "python/ray/_raylet.pyx", line 586, in ray._raylet.check_status
2024-08-14 23:24:49 File "python/ray/_raylet.pyx", line 2794, in ray._raylet.GcsClient.internal_kv_get
2024-08-14 23:24:49 File "python/ray/_raylet.pyx", line 2689, in ray._raylet._auto_reconnect.wrapper
2024-08-14 23:24:49 File "python/ray/_raylet.pyx", line 2712, in ray._raylet._auto_reconnect.wrapper
2024-08-14 23:24:49 result = self.fn(*self.args, **self.kwargs)
2024-08-14 23:24:49 File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run
2024-08-14 23:24:49 return await self.loop.run_in_executor(self.executor, func, *args, **kwargs)
2024-08-14 23:24:49 File "/home/ray/virtualenv/lib/python3.10/site-packages/ray/_private/gcs_aio_client.py", line 33, in wrapper
2024-08-14 23:24:49 return await self._async_proxy.internal_kv_get(key, namespace, timeout)
2024-08-14 23:24:49 File "/home/ray/virtualenv/lib/python3.10/site-packages/ray/_private/gcs_aio_client.py", line 85, in internal_kv_get
2024-08-14 23:24:49 serialized_info = await self._gcs_aio_client.internal_kv_get(
2024-08-14 23:24:49 File "/home/ray/virtualenv/lib/python3.10/site-packages/ray/dashboard/modules/job/common.py", line 218, in get_info
2024-08-14 23:24:49 job_info = await self.get_info(job_id)
2024-08-14 23:24:49 File "/home/ray/virtualenv/lib/python3.10/site-packages/ray/dashboard/modules/job/common.py", line 268, in get_status
2024-08-14 23:24:49 job_status = await self._job_info_client.get_status(job_id)
2024-08-14 23:24:49 File "/home/ray/virtualenv/lib/python3.10/site-packages/ray/dashboard/modules/job/job_manager.py", line 159, in _monitor_job_internal
2024-08-14 23:24:49 Traceback (most recent call last):
2024-08-14 23:24:49 future: <Task finished name='Task-38' coro=<JobManager._monitor_job() done, defined at /home/ray/virtualenv/lib/python3.10/site-packages/ray/dashboard/modules/job/job_manager.py:127> exception=RpcError('Deadline Exceeded')>
it's in the job_info_client
Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Alexey Kudinkin <[email protected]>
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
|
|
This pull request has been automatically closed because there has been no more activity in the 14 days Please feel free to reopen or open a new pull request if you'd still like this to be addressed. Again, you can always ask for help on our discussion forum or Ray's public slack channel. Thanks again for your contribution! |
Fixes #65608. ## Problem `JobManager` records the head's GCS address at construction and passes it to every detached `JobSupervisor`, which builds its own `GcsClient` from it: ```python # job_manager.py self._gcs_address = gcs_client.address ... supervisor = self._supervisor_actor_cls.options(...).remote( submission_id, entrypoint, metadata or {}, self._gcs_address, self._cluster_id_hex, self._logs_dir, ) # job_supervisor.py gcs_client = GcsClient(address=gcs_address, cluster_id=cluster_id_hex) ``` With GCS fault tolerance the head pod can be replaced while a job keeps running on a worker. The worker's raylet and CoreWorker reconnect through the stable head service, but the supervisor's separately constructed client stays pinned to the old address. When the entrypoint exits with code 0, `put_status(SUCCEEDED)` times out, the broad exception handler writes `FAILED`, and the job is reported as `JOB_SUPERVISOR_ACTOR_DIED` despite having succeeded. ## Fix Use the GCS client already configured for the worker process hosting the actor, which reconnects through the stable head service: ```python gcs_client = ray._private.worker.global_worker.gcs_client ``` `gcs_address` and `cluster_id_hex` existed only to build that client, so they are removed from the supervisor's signature and from the `JobManager` side. The same file already uses worker-local state a few lines below (`ray._private.worker.global_worker.node`), so this follows existing practice here. Net -4 lines. ## Not a duplicate `#65027` also concerns jobs during GCS failover, but patches `job_manager.py`'s monitor loop to retry transient gRPC errors. This patches `job_supervisor.py`'s client construction. They are complementary: retries in the monitor cannot help a supervisor whose own client is pinned to an address nothing is listening on. No other open PR references #65608. `gh pr list --search "job_supervisor"` and `--search "JobSupervisor gcs"` surfaced only #65006, #47166, #61099 and #65027, none of which touch this client construction. ## Testing Added `test_job_succeeds_when_manager_gcs_address_is_stale` in `python/ray/dashboard/modules/job/tests/test_job_manager.py`. The full reported path needs KubeRay with GCS FT and a head replacement; the essential condition is that the address the manager recorded is unusable while the worker's own client still works. `_StaleAddressGcsClient` wraps the live client and reports `127.0.0.1:1`, which is reserved and never bound. ``` python -m pytest python/ray/dashboard/modules/job/tests/test_job_manager.py -k stale -q ``` - on master: `1 failed` — the supervisor cannot persist the terminal status - with this change: `1 passed` in 12.70s Surrounding tests that exercise supervisor construction, job submission, supervisor logging and the existing failover path: ``` python -m pytest python/ray/dashboard/modules/job/tests/test_job_manager.py -q -p no:randomly \ -k "stale or network_fault_tolerance or supervisor_log_json or supervisor_logs_saved \ or submit_no_ray_address or get_all_job_info" 7 passed, 63 deselected in 82.54s ``` Lint, using the repo's own configuration: ``` pre-commit run --files python/ray/dashboard/modules/job/job_supervisor.py \ python/ray/dashboard/modules/job/job_manager.py \ python/ray/dashboard/modules/job/tests/test_job_manager.py ruff / pydoclint / black / Ray docstyle / semgrep / import order: all Passed ``` I did not get a clean full-module run locally: `test_job_manager.py` in its entirety stalls on this machine shortly after start (pytest idle at 0% CPU, no Ray processes alive) both with and without this change, so it looks unrelated to it. Happy to run anything specific a reviewer wants. Ray installed as `ray[default]` 2.58.0 with `python/ray/setup-dev.py` symlinks; tested on macOS (Apple silicon). ## Out of scope The `except Exception` handler in `JobSupervisor.run` reclassifies a failure to *persist* an already-known result as `JOB_ENTRYPOINT_COMMAND_START_ERROR`. That is a real second defect, but transient-error handling in this area is the subject of #65027, so it is left alone here to avoid a collision. ## AI usage AI assistance was used for the investigation, the code change, and the test. I reviewed every changed line, ran the commands above myself, and can explain and defend the change. Signed-off-by: Roshan Sharma <[email protected]>
…oject#65686) Fixes ray-project#65608. ## Problem `JobManager` records the head's GCS address at construction and passes it to every detached `JobSupervisor`, which builds its own `GcsClient` from it: ```python # job_manager.py self._gcs_address = gcs_client.address ... supervisor = self._supervisor_actor_cls.options(...).remote( submission_id, entrypoint, metadata or {}, self._gcs_address, self._cluster_id_hex, self._logs_dir, ) # job_supervisor.py gcs_client = GcsClient(address=gcs_address, cluster_id=cluster_id_hex) ``` With GCS fault tolerance the head pod can be replaced while a job keeps running on a worker. The worker's raylet and CoreWorker reconnect through the stable head service, but the supervisor's separately constructed client stays pinned to the old address. When the entrypoint exits with code 0, `put_status(SUCCEEDED)` times out, the broad exception handler writes `FAILED`, and the job is reported as `JOB_SUPERVISOR_ACTOR_DIED` despite having succeeded. ## Fix Use the GCS client already configured for the worker process hosting the actor, which reconnects through the stable head service: ```python gcs_client = ray._private.worker.global_worker.gcs_client ``` `gcs_address` and `cluster_id_hex` existed only to build that client, so they are removed from the supervisor's signature and from the `JobManager` side. The same file already uses worker-local state a few lines below (`ray._private.worker.global_worker.node`), so this follows existing practice here. Net -4 lines. ## Not a duplicate `ray-project#65027` also concerns jobs during GCS failover, but patches `job_manager.py`'s monitor loop to retry transient gRPC errors. This patches `job_supervisor.py`'s client construction. They are complementary: retries in the monitor cannot help a supervisor whose own client is pinned to an address nothing is listening on. No other open PR references ray-project#65608. `gh pr list --search "job_supervisor"` and `--search "JobSupervisor gcs"` surfaced only ray-project#65006, ray-project#47166, ray-project#61099 and ray-project#65027, none of which touch this client construction. ## Testing Added `test_job_succeeds_when_manager_gcs_address_is_stale` in `python/ray/dashboard/modules/job/tests/test_job_manager.py`. The full reported path needs KubeRay with GCS FT and a head replacement; the essential condition is that the address the manager recorded is unusable while the worker's own client still works. `_StaleAddressGcsClient` wraps the live client and reports `127.0.0.1:1`, which is reserved and never bound. ``` python -m pytest python/ray/dashboard/modules/job/tests/test_job_manager.py -k stale -q ``` - on master: `1 failed` — the supervisor cannot persist the terminal status - with this change: `1 passed` in 12.70s Surrounding tests that exercise supervisor construction, job submission, supervisor logging and the existing failover path: ``` python -m pytest python/ray/dashboard/modules/job/tests/test_job_manager.py -q -p no:randomly \ -k "stale or network_fault_tolerance or supervisor_log_json or supervisor_logs_saved \ or submit_no_ray_address or get_all_job_info" 7 passed, 63 deselected in 82.54s ``` Lint, using the repo's own configuration: ``` pre-commit run --files python/ray/dashboard/modules/job/job_supervisor.py \ python/ray/dashboard/modules/job/job_manager.py \ python/ray/dashboard/modules/job/tests/test_job_manager.py ruff / pydoclint / black / Ray docstyle / semgrep / import order: all Passed ``` I did not get a clean full-module run locally: `test_job_manager.py` in its entirety stalls on this machine shortly after start (pytest idle at 0% CPU, no Ray processes alive) both with and without this change, so it looks unrelated to it. Happy to run anything specific a reviewer wants. Ray installed as `ray[default]` 2.58.0 with `python/ray/setup-dev.py` symlinks; tested on macOS (Apple silicon). ## Out of scope The `except Exception` handler in `JobSupervisor.run` reclassifies a failure to *persist* an already-known result as `JOB_ENTRYPOINT_COMMAND_START_ERROR`. That is a real second defect, but transient-error handling in this area is the subject of ray-project#65027, so it is left alone here to avoid a collision. ## AI usage AI assistance was used for the investigation, the code change, and the test. I reviewed every changed line, ran the commands above myself, and can explain and defend the change. Signed-off-by: Roshan Sharma <[email protected]>
Why are these changes needed?
These changes add retries to
JobManagerwhen pingingJobSupervisorto prevent occasions when a single RPC failure leads to a job wrongfully being declared as failed.Related issue number
Checks
git commit -s) in this PR.scripts/format.shto lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/under thecorresponding
.rstfile.