Skip to content

[core] Fix the race condition in the new resource broadcasting. - #32798

Merged
fishbone merged 12 commits into
ray-project:masterfrom
fishbone:fix-race-conditions
Feb 24, 2023
Merged

[core] Fix the race condition in the new resource broadcasting.#32798
fishbone merged 12 commits into
ray-project:masterfrom
fishbone:fix-race-conditions

Conversation

@fishbone

@fishbone fishbone commented Feb 24, 2023

Copy link
Copy Markdown
Contributor

Why are these changes needed?

The root cause is that disconnect is called not in io_context which in the end accessing the invalid memory. Disconnect needs to be called exactly once.

In gRPC, read/write might error and OnCancel also means error just with different semantics. But we need to ensure disconnect is only called once. Previously, disconnect might be called in gRPC threads, main thread/... and this PR enforce them called within the io context.

This fix the release test long_running_node_failures.

Related issue number

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

@fishbone

Copy link
Copy Markdown
Contributor Author

It's a race condition and so hard to add a unit test for this. let me know if anyone has good ideas.

@fishbone

fishbone commented Feb 24, 2023

Copy link
Copy Markdown
Contributor Author

@rkooo567 rkooo567 left a comment

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.

The change itself lgtm. But this makes me think it's probably better making the module thread-safe rather than relying on posting to the io service? Seems like the threading model is very prone to error rn (I know it is a common problem in Ray, but I am bringing this up because it is a new module and we can enforce some good practice here?)

@rkooo567 rkooo567 added the @author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer. label Feb 24, 2023
@fishbone

Copy link
Copy Markdown
Contributor Author

@rkooo567 making it thread safe is the same as posting things to io-context. Basically, you can replace posting => mutex lock. So that's why I'm not putting mutex there.

And issues come from gRPC's callback is in gRPC thread. A good practice from gRPC is that don't hold the thread for long time.

IMPORTANT USAGE NOTE : code in any reaction must not block for an arbitrary amount of time since reactions are executed on a finite-sized, library-controlled threadpool. If any long-term blocking operations (like sleeps, file I/O, synchronous RPCs, or waiting on a condition variable) must be invoked as part of the application logic, then it is important to push that outside the reaction so that the reaction can complete in a timely fashion. One way of doing this is to push that code to a separate application-controlled thread.

The concerns or the difficulties should be handled in gRPC/threading related work.

@fishbone

Copy link
Copy Markdown
Contributor Author

Hmmm, the test entered the terminated status... Seems the cluster is terminated... I'll check what's going on there.

@fishbone

Copy link
Copy Markdown
Contributor Author

I think it might be related to the migration to jobs on v2. Let me check.

@fishbone

Copy link
Copy Markdown
Contributor Author

Confirmed that it's an infra issue. Merge this one.

@fishbone
fishbone merged commit ceafef8 into ray-project:master Feb 24, 2023
edoakes pushed a commit to edoakes/ray that referenced this pull request Mar 22, 2023
…project#32798)

The root cause is that disconnect is called not in io_context which in the end accessing the invalid memory. Disconnect needs to be called exactly once.

In gRPC, read/write might error and OnCancel also means error just with different semantics. But we need to ensure disconnect is only called once. Previously, disconnect might be called in gRPC threads, main thread/... and this PR enforce them called within the io context.

This fix the release test long_running_node_failures.

Signed-off-by: Edward Oakes <ed.nmi.oakes@gmail.com>
peytondmurray pushed a commit to peytondmurray/ray that referenced this pull request Mar 22, 2023
…project#32798)

The root cause is that disconnect is called not in io_context which in the end accessing the invalid memory. Disconnect needs to be called exactly once.

In gRPC, read/write might error and OnCancel also means error just with different semantics. But we need to ensure disconnect is only called once. Previously, disconnect might be called in gRPC threads, main thread/... and this PR enforce them called within the io context.

This fix the release test long_running_node_failures.
elliottower pushed a commit to elliottower/ray that referenced this pull request Apr 22, 2023
…project#32798)

The root cause is that disconnect is called not in io_context which in the end accessing the invalid memory. Disconnect needs to be called exactly once.

In gRPC, read/write might error and OnCancel also means error just with different semantics. But we need to ensure disconnect is only called once. Previously, disconnect might be called in gRPC threads, main thread/... and this PR enforce them called within the io context.

This fix the release test long_running_node_failures.

Signed-off-by: elliottower <elliot@elliottower.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

@author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants