Skip to content

Improving message for access to unknown objects - #28209

Merged
jjyao merged 20 commits into
ray-project:masterfrom
pabloem:patch-1
Dec 18, 2022
Merged

jjyao merged 20 commits into
ray-project:masterfrom
pabloem:patch-1

Conversation

@pabloem

@pabloem pabloem commented Aug 31, 2022 •

Copy link
Copy Markdown
Contributor

Signed-off-by: Pablo [email protected]

Why are these changes needed?

Consider this scenario:


ray.init()
my_objref = ray.put('MY TEXT')
ray.shutdown()

ray.init()

@ray.remote
def my_fn(obj):
  print(obj)

my_fn.remote(my_objref)

In this scenario, Ray will throw this error and kill the Python interpreter (without erroring out!). I've tried to rephrase the error to be a little easier to figure out and fix, and changed the check so that an error will be thrown rather than ending the whole process.


Changes to Ray APIs

The best overview you can get is by checking the changes to test_ray_shutdown.py. The behavior changes in the following scenarios:

First consider the following set up:

ray.init()
my_ref = ray.put("anystring")

@ray.remote
def f(s):
    print(s)

ray.shutdown()

ray.init()

In this case, my_ref is an ObjRef that exists from a previous Ray session, and start a new ray session that does not know this object. Without this change, the behavior is:

Call Result
f.remote([my_ref]) This would cause the Python interpreter to die
f.remote(my_ref) This would cause the Python interpreter to die
ray.get(my_ref, timeout=30) This would cause Ray to throw a Timeout exception
ray.get(my_ref) This would cause Ray to hang indefinitely
ray.wait([my_ref]) This would cause Ray to hang indefinitely
ray.wait([my_ref], timeout=30) This would cause Ray to throw a timeout
ray.wait([ray.put("something"), my_ref]) This would cause Ray to always return ObjRef("something")
ray.wait([ray.put("something"), my_ref], num_returns=2) This would cause Ray hang indefinitely

With these changes, the behavior for each call is now:

Call Result
f.remote([my_ref]) Throws ValueError with the expected explanation
f.remote(my_ref) Throws ValueError with the expected explanation
ray.get(my_ref, timeout=30) Throws ValueError with the expected explanation
ray.get(my_ref) Throws ValueError with the expected explanation
ray.wait([my_ref]) Throws ValueError with the expected explanation
ray.wait([my_ref], timeout=30) Throws ValueError with the expected explanation
ray.wait([ray.put("something"), my_ref]) This would cause Ray to always return ObjRef("something")
ray.wait([ray.put("something"), my_ref], num_returns=2) Throws ValueError with the expected explanation

I would argue that this change is preferable from the previous behavior because:

  • Python interpreter dying is never an expected outcome for a Python application.
  • Rather than hanging indefinitely, users now can know that the object they're requesting will never be available

That's it, I think.

(FYI on above section @stephanie-wang @jjyao)

Related issue number

I have not created an issue to track this.

Checks

@pabloem pabloem changed the title [wip] Improving message for access to unknown objects Improving message for access to unknown objects Sep 7, 2022
@pabloem

pabloem commented Sep 7, 2022

Copy link
Copy Markdown
Contributor Author

This is meant to fix #28211 - how can I run the test I added to verify that?

r: @jjyao

@pabloem
pabloem marked this pull request as ready for review September 7, 2022 17:01
@pabloem

pabloem commented Sep 7, 2022

Copy link
Copy Markdown
Contributor Author

I also added a test for #28341, but I have not added a fix

@pabloem

pabloem commented Sep 7, 2022

Copy link
Copy Markdown
Contributor Author

hm I see this does not raise an error either. How can I raise a Python error from C? : )

@richardliaw

Copy link
Copy Markdown
Contributor

@jjyao could you shepherd this?

@jjyao jjyao self-assigned this Sep 7, 2022
@pabloem
pabloem force-pushed the patch-1 branch 2 times, most recently from d3ec300 to d45ee06 Compare September 8, 2022 05:41
@jjyao

jjyao commented Sep 8, 2022

Copy link
Copy Markdown
Contributor

Sorry for the late review. I'll take a look tomorrow!

@pabloem

pabloem commented Sep 8, 2022

Copy link
Copy Markdown
Contributor Author

question:
I'm running the following:

bazel build -- //:ray_pkg //cpp:ray_cpp_pkg
pip install -e python/.
python -m pytest -v -s python/ray/tests/test_ray_shutdown.py

This works for my purposes, but it won't build Ray with all the compilation checks (e.g. -Wunused-result) - do you know what I might need for that?

@pabloem

pabloem commented Sep 8, 2022

Copy link
Copy Markdown
Contributor Author

ok at this point the failing tests seem like unrelated flakes. LMK if I should look into it!

(also, I'll sign the commit on the next review cycle)

@jjyao

jjyao commented Sep 9, 2022

Copy link
Copy Markdown
Contributor

I actually think the check failure is fine here: you should never share the object ref out of band across clusters. If you do that then it's a bug in the application code and the check failure basically tells you to fix the application code. IMO, it probably doesn't worth the effort to propagate up a catchable exception (it doesn't make much sense to catch and recover from it, we should just fix the application code).

Maybe we should just improve the check failure message? WDYT @stephanie-wang ?

@pcmoritz

pcmoritz commented Sep 9, 2022 •

Copy link
Copy Markdown
Contributor

Hmm, it seems to me that having a Python program just terminate the interpreter is always bad and raising and exception is much preferable. I haven't reviewed the PR in detail but it doesn't seem to introduce that much complexity. So we should probably merge it.

While it doesn't make sense to catch the exception and recover from it, raising an exception is always better than just terminating the interpreter. Python is a safe language, so it shouldn't crash.

@pabloem

pabloem commented Sep 9, 2022

Copy link
Copy Markdown
Contributor Author

Thanks! Right, I don't think the python interpreter should ever just terminate like that, but rather throw a Python exception that will tell the application what is the problem. I've added a couple small tests that you can try in Ray without this change and see how the behavior without the change is at least unintuitive

(p.s. pushed signed-off commit)

@jjyao

jjyao commented Sep 9, 2022 •

Copy link
Copy Markdown
Contributor

Ok, then I think we should check all the public apis that accept obj refs or nested obj refs and make sure they all throw the exception instead of check failure.

@pabloem

pabloem commented Sep 9, 2022

Copy link
Copy Markdown
Contributor Author

I've created a GetOwnerAddressOrDie method which will preserve the existing behavior for untested paths, and used GetOwnerAddress for paths that we can test. Do you think we could review the current scope of changes and have a follow-up item to review other API paths that may cause CPython death afterwards? : )

Comment thread python/ray/_raylet.pyx Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we add possible reasons why this can happen to the message just like the check failure message?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done.

Comment thread python/ray/_raylet.pyx Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We don't need to check status here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've added the check there. This should be more reasonable, huh?

Comment thread python/ray/_raylet.pyx Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this exception is for a different purpose based on its comment. Should it just be ValueError given that we pass invalid objects to the functions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

that makes sense. done.

Comment thread python/ray/tests/test_ray_shutdown.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we add a similar test for ray.wait() as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added one. please make sure to check on the behavior and lmk if it makes sense to you.

Comment thread python/ray/tests/test_ray_shutdown.py Resolved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I feel a bool is enough here based on the function name?

Also I feel we can expose an ObjectHasOwner method in core_worker and do the validation at the beginning of public apis like ray.get() (normally where we do function inputs validation) so the remaining code can just assume the objects are always valid and we have a single logic deciding whether an object is valid. WDYT?

Comment thread python/ray/tests/test_ray_shutdown.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we check more specifically to make sure the exact error is thrown, RayError is too broad. We can even check the exception message.

Btw, you can use with pytest.raises(...)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done. thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm, I think abort_if_any_object_is_exception and abort_if_missing are two different things.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok I've changed this

@jjyao

jjyao commented Sep 13, 2022

Copy link
Copy Markdown
Contributor

Do you think we could review the current scope of changes and have a follow-up item to review other API paths that may cause CPython death afterwards? : )

sg :)

@pabloem

pabloem commented Oct 10, 2022

Copy link
Copy Markdown
Contributor Author

@jjyao any pointers for me to look at reproducing any possible failures locally? : )

@pabloem

pabloem commented Nov 1, 2022

Copy link
Copy Markdown
Contributor Author

@jjyao ptal? : )

@pabloem

pabloem commented Nov 1, 2022

Copy link
Copy Markdown
Contributor Author

i'll try to debug why the tests are not passing as expected...

@jjyao

jjyao commented Nov 1, 2022

Copy link
Copy Markdown
Contributor

sorry for dropping the ball here, I'll take a look at the failures as well.

@pabloem

pabloem commented Dec 15, 2022

Copy link
Copy Markdown
Contributor Author

rebased!

I think this should be ready : ) @jjyao thanks

@pabloem pabloem closed this Dec 15, 2022
@pabloem pabloem reopened this Dec 15, 2022
@pabloem

pabloem commented Dec 15, 2022

Copy link
Copy Markdown
Contributor Author

reopening to rernu tests.......

Signed-off-by: Pablo E <[email protected]>
@pabloem
pabloem requested a review from jjyao December 16, 2022 01:28
@pabloem

pabloem commented Dec 16, 2022

Copy link
Copy Markdown
Contributor Author

ok looks good finally : )

Comment thread src/ray/core_worker/core_worker.cc Outdated
for (size_t i = 0; i < ids.size(); i++) {
rpc::Address unused_owner_address;
auto status = GetOwnerAddress(ids[i], &unused_owner_address);
if (!status.ok()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of not ok, can we check ObjectUnknownOwner explicitly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread src/ray/core_worker/core_worker.cc Outdated
for (size_t i = 0; i < ids.size(); i++) {
rpc::Address unused_owner_address;
auto status = GetOwnerAddress(ids[i], &unused_owner_address);
if (!status.ok()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@jjyao

jjyao commented Dec 16, 2022

Copy link
Copy Markdown
Contributor

Tests look good. I manually triggered mac tests, lets see if they are passing as well.

@pabloem

pabloem commented Dec 17, 2022

Copy link
Copy Markdown
Contributor Author

Signed-off-by: Pablo E <[email protected]>
@jjyao
jjyao merged commit d57b582 into ray-project:master Dec 18, 2022
@jjyao

jjyao commented Dec 18, 2022

Copy link
Copy Markdown
Contributor

Thanks!!

@pabloem
pabloem deleted the patch-1 branch December 18, 2022 14:57
WeichenXu123 pushed a commit to WeichenXu123/ray that referenced this pull request Dec 19, 2022
While working on ray-project#28209 I hit issue google/googletest#3514, which causes a couple gtest-dependent tests to be unable to build

Signed-off-by: Pablo E <[email protected]>
Signed-off-by: Weichen Xu <[email protected]>
rickyyx added a commit that referenced this pull request Jan 3, 2023
AmeerHajAli pushed a commit that referenced this pull request Jan 12, 2023
Signed-off-by: Pablo E <[email protected]>

When accessing unknown objects, Ray will kill the Python interpreter (without erroring out!). I've tried to rephrase the error to be a little easier to figure out and fix, and changed the check so that an error will be thrown rather than ending the whole process.
tamohannes pushed a commit to ju2ez/ray that referenced this pull request Jan 25, 2023
Signed-off-by: Pablo E <[email protected]>

When accessing unknown objects, Ray will kill the Python interpreter (without erroring out!). I've tried to rephrase the error to be a little easier to figure out and fix, and changed the check so that an error will be thrown rather than ending the whole process.

Signed-off-by: tmynn <[email protected]>
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.

4 participants