Repository navigation
[jobs] Fix recovery race condition in JobManager - #40068
Conversation
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
JobManagerJobManager
JobManagerJobManager
Signed-off-by: Edward Oakes <[email protected]>
There was a problem hiding this comment.
Hmm I may be misunderstaing some parts, but is there a repro + test we can add, or is it purely a theoretical fix?
I have 2 parts that I feel sketchy;
- Currently
run_background_task(self._monitor_job(job_id))startsmonitor_jobasynchronously, so although we have this event, there's still a possibility_monitor_job_internalis triggered between Put job info <> actor creation? - This part of code
if job_supervisor is None:
job_supervisor = self._get_actor_for_job(job_id)
if job_supervisor is None:
if job_status == JobStatus.PENDING:
# Maybe the job supervisor actor is not created yet.
# We will wait for the next loop.
continue
should avoid the race you mentioned from the original issue (because we never overwrites the PENDING state to others until we create an actor iiuc)?
I am actually curious if it is just
- supervisor actor is removed somehow (killed, failed to start, or whatever) after it is added to the monitor loop.
- monitor job "overwrites" the already failed job. It seems like the current logic allows to do it.
|
@rkooo567 the race condition happens because the background task is started for the pending job. The fix in this PR will avoid kicking off the The So sequence of events is:
|
|
So, it looks like if a supervisor actor fails to start, I can easily reproduce the error message. Can you add a unit test? (maybe we can provide a bad runtime env to the supervisor actor). I could verify this PR fixes the issue. Regarding the problem, I have the impression the root cause is actually that we don't health check actor right after we create it, but we rely on monitor_internal which always calls Regarding the current fix, I could verify the fix, but I feel like there's still fundamental possibility of race. The reason why I feel this way is because "monitor_job" is a task, so theoretically it is still able to be created in the middle of PENDING <> actor creation (since we await on putting the PENDING status RPC). For example, I feel like the following scenario is possible.
|
rkooo567
left a comment
There was a problem hiding this comment.
Since the current fix seems to work, I will leave it up to you which solution you chooses, but let's add a unit test before merging it!
For a single job manager, this sequence of events cannot happen for a single Re: your proposed solution about health checking immediately after starting the actor, that is effectively what happens in this case (with a bad |
|
@rkooo567 I've added a test case: Verified that this failed consistently w/o the fix. |
Signed-off-by: Edward Oakes <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
architkulkarni
left a comment
There was a problem hiding this comment.
Fix was discussed offline. Nice test!
Why are these changes needed?
There are multiple race conditions between
JobManager.submit_jobandJobManager._recover_running_jobsbecause the latter runs as an async task on the event loop. This can cause a duplicate monitoring task to be started for a job before the actor is event spawned. This has caused multiple issues:JobManagerbetween_recover_running_jobsandsubmit_job#40062This PR adds synchronization so
submit_jobwill only run after_recover_running_jobsfinishes (note that_recover_running_jobsis async and will exit after a single GCS read RPC, so this should have no practical impact).Related issue number
Closes #40062
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.