[Core] Support UTF-8 Actor Creation Exceptions (#21807)

Now if an actor throws an exception containing non-ASCII characters, the actor won't die and will be alive.

This is because the following exception occurred during handling the user's exception:
```
  File "python/ray/_raylet.pyx", line 587, in ray._raylet.task_execution_handler
  File "python/ray/_raylet.pyx", line 434, in ray._raylet.execute_task
  File "python/ray/_raylet.pyx", line 551, in ray._raylet.execute_task
  File "/home/admin/.local/lib/python3.6/site-packages/ray/utils.py", line 96, in push_error_to_driver
    worker.core_worker.push_error(job_id, error_type, message, time.time())
  File "python/ray/_raylet.pyx", line 1636, in ray._raylet.CoreWorker.push_error
UnicodeEncodeError: 'ascii' codec can't encode characters in position 2597-2600: ordinal not in range(128)
An unexpected internal error occurred while the worker was executing a task.
```

This PR fixes this issue.
This commit is contained in:
Lixin Wei 2022-01-25 12:27:43 +08:00 committed by GitHub
parent 089f49f554
commit bc55a958c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View file

@ -2148,8 +2148,8 @@ cdef class CoreWorker:
def push_error(self, JobID job_id, error_type, error_message,
double timestamp):
check_status(CCoreWorkerProcess.GetCoreWorker().PushError(
job_id.native(), error_type.encode("ascii"),
error_message.encode("ascii"), timestamp))
job_id.native(), error_type.encode("utf-8"),
error_message.encode("utf-8"), timestamp))
def get_job_config(self):
cdef CJobConfig c_job_config

View file

@ -728,6 +728,20 @@ def test_actor_failure_per_type(ray_start_cluster):
print(exc_info._excinfo[1])
def test_utf8_actor_exception(ray_start_regular):
@ray.remote
class FlakyActor:
def __init__(self):
raise RuntimeError("你好呀,祝你有个好心情!")
def ping(self):
return True
actor = FlakyActor.remote()
with pytest.raises(ray.exceptions.RayActorError):
ray.get(actor.ping.remote())
if __name__ == "__main__":
import pytest
sys.exit(pytest.main(["-v", __file__]))