Skip to content

[Core] Fix race condition in multi-threaded actor creation#44232

Merged
jjyao merged 10 commits intoray-project:masterfrom
ruisearch42:actor_threads_fix
Mar 25, 2024
Merged

[Core] Fix race condition in multi-threaded actor creation#44232
jjyao merged 10 commits intoray-project:masterfrom
ruisearch42:actor_threads_fix

Conversation

@ruisearch42
Copy link
Copy Markdown
Contributor

@ruisearch42 ruisearch42 commented Mar 21, 2024

Why are these changes needed?

This is to fix race condition in multi-threaded actor creation. The race condition is between
setting and checking meta.last_export_session_and_job, specifically:

When thread1 is exporting the actor by calling worker.function_actor_manager.export_actor_class in the following block:

        if not meta.is_cross_language and (
            meta.last_export_session_and_job != worker.current_session_and_job
        ):
            meta.last_export_session_and_job = worker.current_session_and_job
            worker.function_actor_manager.export_actor_class(
                meta.modified_class,
                meta.actor_creation_function_descriptor,
                meta.method_meta.methods.keys(),
            )

Thread2 could be executing the if condition in the above code (which evaluates to False) and continue to create the actor, however thread2 will fail with an AssersionError later (aborts the process) as it expects the actor to be already exported.

This code fixes the race condition by setting the flag meta.last_export_session_and_job only when the export is done. More details can be found at #41324 .

Related issue number

Closes #41324

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • Run the script that exposes this problem 100 times and all passed
    • This PR is not tested :(

Signed-off-by: Rui Qiao <ruisearch42@gmail.com>
Signed-off-by: Rui Qiao <ruisearch42@gmail.com>
Signed-off-by: Rui Qiao <ruisearch42@gmail.com>
Signed-off-by: Rui Qiao <ruisearch42@gmail.com>
Signed-off-by: Rui Qiao <ruisearch42@gmail.com>
Copy link
Copy Markdown
Contributor

@fishbone fishbone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG. Make sure the test pass.

ruisearch42 and others added 5 commits March 22, 2024 14:51
Signed-off-by: Rui Qiao <ruisearch42@gmail.com>
Signed-off-by: Rui Qiao <ruisearch42@gmail.com>
Signed-off-by: Rui Qiao <ruisearch42@gmail.com>
Signed-off-by: Rui Qiao <ruisearch42@gmail.com>
@jjyao jjyao merged commit e75b97b into ray-project:master Mar 25, 2024
stephanie-wang pushed a commit to stephanie-wang/ray that referenced this pull request Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Core] getting/creating an actor from multiple thread errors

3 participants