-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Core] Fix check failure: sync_reactors_.find(reactor->GetRemoteNodeID()) == sync_reactors_.end() #47861
Merged
Merged
[Core] Fix check failure: sync_reactors_.find(reactor->GetRemoteNodeID()) == sync_reactors_.end() #47861
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
38c6ec2
Fix check failure: sync_reactors_.find(reactor->GetRemoteNodeID()) ==…
jjyao f572f84
up
jjyao a5042b8
test
jjyao 52b8d9e
fix
jjyao b2997b8
up
jjyao ab293fa
fix
jjyao 26aaf91
comment
jjyao 599f50b
experiment
jjyao 867a47f
up
jjyao 3ff5233
Merge branch 'master' of github.com:ray-project/ray into jjyao/synnner
jjyao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,7 +96,7 @@ RayServerBidiReactor::RayServerBidiReactor( | |
instrumented_io_context &io_context, | ||
const std::string &local_node_id, | ||
std::function<void(std::shared_ptr<const RaySyncMessage>)> message_processor, | ||
std::function<void(const std::string &, bool)> cleanup_cb) | ||
std::function<void(RaySyncerBidiReactor *, bool)> cleanup_cb) | ||
: RaySyncerBidiReactorBase<ServerBidiReactor>( | ||
io_context, | ||
GetNodeIDFromServerContext(server_context), | ||
|
@@ -122,7 +122,7 @@ void RayServerBidiReactor::OnCancel() { | |
void RayServerBidiReactor::OnDone() { | ||
io_context_.dispatch( | ||
[this, cleanup_cb = cleanup_cb_, remote_node_id = GetRemoteNodeID()]() { | ||
cleanup_cb(remote_node_id, false); | ||
cleanup_cb(this, false); | ||
delete this; | ||
}, | ||
""); | ||
|
@@ -133,7 +133,7 @@ RayClientBidiReactor::RayClientBidiReactor( | |
const std::string &local_node_id, | ||
instrumented_io_context &io_context, | ||
std::function<void(std::shared_ptr<const RaySyncMessage>)> message_processor, | ||
std::function<void(const std::string &, bool)> cleanup_cb, | ||
std::function<void(RaySyncerBidiReactor *, bool)> cleanup_cb, | ||
std::unique_ptr<ray::rpc::syncer::RaySyncer::Stub> stub) | ||
: RaySyncerBidiReactorBase<ClientBidiReactor>( | ||
io_context, remote_node_id, std::move(message_processor)), | ||
|
@@ -151,7 +151,7 @@ RayClientBidiReactor::RayClientBidiReactor( | |
void RayClientBidiReactor::OnDone(const grpc::Status &status) { | ||
io_context_.dispatch( | ||
[this, status]() { | ||
cleanup_cb_(GetRemoteNodeID(), !status.ok()); | ||
cleanup_cb_(this, !status.ok()); | ||
delete this; | ||
}, | ||
""); | ||
|
@@ -221,7 +221,13 @@ void RaySyncer::Connect(const std::string &node_id, | |
/* io_context */ io_context_, | ||
/* message_processor */ [this](auto msg) { BroadcastRaySyncMessage(msg); }, | ||
/* cleanup_cb */ | ||
[this, channel](const std::string &node_id, bool restart) { | ||
[this, channel](RaySyncerBidiReactor *reactor, bool restart) { | ||
const std::string &node_id = reactor->GetRemoteNodeID(); | ||
if (sync_reactors_.contains(node_id) && | ||
sync_reactors_.at(node_id) != reactor) { | ||
// The client is already reconnected. | ||
return; | ||
} | ||
sync_reactors_.erase(node_id); | ||
if (restart) { | ||
execute_after( | ||
|
@@ -247,7 +253,7 @@ void RaySyncer::Connect(RaySyncerBidiReactor *reactor) { | |
boost::asio::dispatch( | ||
io_context_.get_executor(), std::packaged_task<void()>([this, reactor]() { | ||
RAY_CHECK(sync_reactors_.find(reactor->GetRemoteNodeID()) == sync_reactors_.end()) | ||
<< reactor->GetRemoteNodeID(); | ||
<< NodeID::FromBinary(reactor->GetRemoteNodeID()); | ||
sync_reactors_[reactor->GetRemoteNodeID()] = reactor; | ||
// Send the view for new connections. | ||
for (const auto &[_, messages] : node_state_->GetClusterView()) { | ||
|
@@ -274,9 +280,7 @@ void RaySyncer::Disconnect(const std::string &node_id) { | |
} | ||
|
||
auto reactor = iter->second; | ||
if (iter != sync_reactors_.end()) { | ||
sync_reactors_.erase(iter); | ||
} | ||
sync_reactors_.erase(iter); | ||
reactor->Disconnect(); | ||
}); | ||
boost::asio::dispatch(io_context_.get_executor(), std::move(task)).get(); | ||
|
@@ -350,14 +354,31 @@ ServerBidiReactor *RaySyncerService::StartSync(grpc::CallbackServerContext *cont | |
syncer_.GetIOContext(), | ||
syncer_.GetLocalNodeID(), | ||
[this](auto msg) mutable { syncer_.BroadcastMessage(msg); }, | ||
[this](const std::string &node_id, bool reconnect) mutable { | ||
[this](RaySyncerBidiReactor *reactor, bool reconnect) mutable { | ||
// No need to reconnect for server side. | ||
RAY_CHECK(!reconnect); | ||
const auto &node_id = reactor->GetRemoteNodeID(); | ||
if (syncer_.sync_reactors_.contains(node_id) && | ||
syncer_.sync_reactors_.at(node_id) != reactor) { | ||
// There is a new connection to the node, no need to clean up. | ||
// This can happen when there is transient network error and the client | ||
// reconnects. The sequence of events are: | ||
// 1. Client reconnects, StartSync is called | ||
// 2. syncer_.Disconnect is called and the old reactor is removed from | ||
// sync_reactors_ | ||
// 3. syncer_.Connect is called and the new reactor is added to sync_reactors_ | ||
// 4. OnDone method of the old reactor is called which calls this cleanup_cb_ | ||
return; | ||
} | ||
syncer_.sync_reactors_.erase(node_id); | ||
syncer_.node_state_->RemoveNode(node_id); | ||
}); | ||
RAY_LOG(INFO).WithField(kLogKeyNodeID, NodeID::FromBinary(reactor->GetRemoteNodeID())) | ||
<< "Get connection"; | ||
// Disconnect exiting connection if there is any. | ||
// This can happen when there is transient network error | ||
// and the client reconnects. | ||
syncer_.Disconnect(reactor->GetRemoteNodeID()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. QQ: why don't we call this in clean_cb? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
syncer_.Connect(reactor); | ||
return reactor; | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test seems very useful. wonder if we should extend it to more e2e tests in some stress tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I'll use the same pattern for other tests. I'm also exploring chaos test tools for randomly injecting network errors.