[core] Increment ref count when creating an ObjectRef to prevent object from going out of scope#21719
Conversation
|
I still need to fix up the ref counting in Java and C++ language frontends, but the Python version is ready for review. |
|
Oh turns out the C++ frontend doesn't actually do ref counting. |
ericl
left a comment
There was a problem hiding this comment.
Looks good, but I don't have the state to give a really detailed review. Maybe trigger nightly tests to flush out any edge cases?
| prepare_args_internal(core_worker, language, args, args_vector, | ||
| function_descriptor, put_arg_ids) | ||
| except Exception as e: | ||
| # An error occurred during arg serialization. We must remove the |
There was a problem hiding this comment.
Hmm, is it possible the refs haven't been added yet?
There was a problem hiding this comment.
We don't add to this list unless we've already incremented the local ref. Updated the variable name to clarify.
|
Ran nightly, I think all of these test failures are from master: |
|
LINT errors, etc. Can you rebase? |
|
|
Test failures look unrelated (on the last commit it passed all but Java, and Java's now passing). |
…ent object from going out of scope (ray-project#21719)" This reverts commit e3af828.
…ct from going out of scope (#22120) When a Ray program first creates an ObjectRef (via ray.put or task call), we add it with a ref count of 0 in the C++ backend because the language frontend will increment the initial local ref once we return the allocated ObjectID, then delete the local ref once the ObjectRef goes out of scope. Thus, there is a brief window where the object ref will appear to be out of scope. This can cause problems with async protocols that check whether the object is in scope or not, such as the previous bug fixed in #19910. Now that we plan to enable lineage reconstruction to automatically recover lost objects, this race condition can also be problematic because we use the ref count to decide whether an object needs to be recovered or not. This PR avoids these race conditions by incrementing the local ref count in the C++ backend when executing ray.put() and task calls. The frontend is then responsible for skipping the initial local ref increment when creating the ObjectRef. This is the same fix used in #19910, but generalized to all initial ObjectRefs. This is a re-merge for #21719 with a fix for removing the owned object ref if creation fails.
…ct from going out of scope (ray-project#22120) When a Ray program first creates an ObjectRef (via ray.put or task call), we add it with a ref count of 0 in the C++ backend because the language frontend will increment the initial local ref once we return the allocated ObjectID, then delete the local ref once the ObjectRef goes out of scope. Thus, there is a brief window where the object ref will appear to be out of scope. This can cause problems with async protocols that check whether the object is in scope or not, such as the previous bug fixed in ray-project#19910. Now that we plan to enable lineage reconstruction to automatically recover lost objects, this race condition can also be problematic because we use the ref count to decide whether an object needs to be recovered or not. This PR avoids these race conditions by incrementing the local ref count in the C++ backend when executing ray.put() and task calls. The frontend is then responsible for skipping the initial local ref increment when creating the ObjectRef. This is the same fix used in ray-project#19910, but generalized to all initial ObjectRefs. This is a re-merge for ray-project#21719 with a fix for removing the owned object ref if creation fails.
Why are these changes needed?
When a Ray program first creates an ObjectRef (via ray.put or task call), we add it with a ref count of 0 in the C++ backend because the language frontend will increment the initial local ref once we return the allocated ObjectID, then delete the local ref once the ObjectRef goes out of scope. Thus, there is a brief window where the object ref will appear to be out of scope.
This can cause problems with async protocols that check whether the object is in scope or not, such as the previous bug fixed in #19910. Now that we plan to enable lineage reconstruction to automatically recover lost objects, this race condition can also be problematic because we use the ref count to decide whether an object needs to be recovered or not.
This PR avoids these race conditions by incrementing the local ref count in the C++ backend when executing ray.put() and task calls. The frontend is then responsible for skipping the initial local ref increment when creating the ObjectRef. This is the same fix used in #19910, but generalized to all initial ObjectRefs.
Checks
scripts/format.shto lint the changes in this PR.