Skip to content

Commit

Permalink
[Core] Fix the GIL deadlock issue caused by list_named_actors. (#45582
Browse files Browse the repository at this point in the history
)

Signed-off-by: hejialing.hjl <hejialing.hjl@bytedance.com>
  • Loading branch information
Catch-Bull committed May 31, 2024
1 parent d6f97cc commit f9ab439
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
5 changes: 3 additions & 2 deletions python/ray/_raylet.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4446,8 +4446,9 @@ cdef class CoreWorker:
cdef:
pair[c_vector[pair[c_string, c_string]], CRayStatus] result_pair

result_pair = CCoreWorkerProcess.GetCoreWorker().ListNamedActors(
all_namespaces)
with nogil:
result_pair = CCoreWorkerProcess.GetCoreWorker().ListNamedActors(
all_namespaces)
check_status(result_pair.second)
return [
(namespace.decode("utf-8"),
Expand Down
31 changes: 31 additions & 0 deletions python/ray/tests/test_list_actors_4.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio
import pytest
import sys
import time

import ray
from ray._private.test_utils import run_string_as_driver
Expand Down Expand Up @@ -52,6 +54,35 @@ class A:
assert not ray.util.list_named_actors(all_namespaces=True)


@pytest.mark.asyncio
async def test_list_named_actors_with_normal_task(shutdown_only):
# The following parameters are all designed to increase the
# probability of reproducing the situation where
# `list_named_actors` gets hang.
# https://github.com/ray-project/ray/issues/45581 for more details.
TEST_RANGE = 10
NORMAL_TASK_PER_ITEM = 100
LIST_NAMED_ACTORS_PER_ITEM = 10
for _ in range(TEST_RANGE):
time.sleep(1)

@ray.remote
def test():
return True

res = []
for i in range(NORMAL_TASK_PER_ITEM):
res.append(test.remote())

async def run():
for i in range(LIST_NAMED_ACTORS_PER_ITEM):
await asyncio.sleep(0)
ray.util.list_named_actors(True)

res.append(run())
await asyncio.gather(*res)


if __name__ == "__main__":
import os

Expand Down

0 comments on commit f9ab439

Please sign in to comment.