Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Resolve the race condition between reference counting GC and actor creation #49480

Merged
merged 4 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions python/ray/tests/test_get_or_create_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,25 @@ def do_run(name):
assert "DONE" in valid, out_str


def test_get_or_create_named_actor(shutdown_only):
"""
This test aggressively gets or creates a named actor and makes the actor
go out of scope immediately. Additionally, `max_restarts=-1` is set to make
the actor restartable and make the test more aggressive.
"""

@ray.remote
class Actor:
pass

for _ in range(1000):
Actor.options(
name="test-get-or-create-named-actor",
get_if_exists=True,
max_restarts=-1,
).remote()


if __name__ == "__main__":
if os.environ.get("PARALLEL_CI"):
sys.exit(pytest.main(["-n", "auto", "--boxed", "-vs", __file__]))
Expand Down
5 changes: 2 additions & 3 deletions src/ray/gcs/gcs_server/gcs_actor_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,7 @@ void GcsActorManager::HandleGetNamedActorInfo(

Status status = Status::OK();
auto iter = registered_actors_.find(actor_id);
if (actor_id.IsNil() || iter == registered_actors_.end() ||
iter->second->GetState() == rpc::ActorTableData::DEAD) {
if (actor_id.IsNil() || iter == registered_actors_.end()) {
// The named actor was not found or the actor is already removed.
std::stringstream stream;
stream << "Actor with name '" << name << "' was not found.";
Expand Down Expand Up @@ -931,7 +930,7 @@ void GcsActorManager::RemoveActorNameFromRegistry(
if (namespace_it != named_actors_.end()) {
auto it = namespace_it->second.find(actor->GetName());
if (it != namespace_it->second.end()) {
RAY_LOG(INFO) << "Actor name " << actor->GetName() << " is cleand up.";
RAY_LOG(INFO) << "Actor name " << actor->GetName() << " is cleaned up.";
namespace_it->second.erase(it);
}
// If we just removed the last actor in the namespace, remove the map.
Expand Down
Loading