Repository navigation
[core] Keep RaySyncer reactors alive for every handler dispatched to io_context #67399
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,8 +55,11 @@ RayClientBidiReactor::RayClientBidiReactor( | |
| } | ||
|
|
||
| void RayClientBidiReactor::OnDone(const grpc::Status &status) { | ||
| // `self` keeps the reactor alive until this handler has finished, including | ||
| // through cleanup_cb_; resetting self_ref_ then drops the last owning | ||
| // reference once the handler returns. | ||
| io_context_.dispatch( | ||
| [this, status]() { | ||
| [this, self = self_ref_, status]() { | ||
| cleanup_cb_(this, !status.ok()); | ||
| self_ref_.reset(); | ||
|
Comment on lines
61
to
64
Contributor
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. To prevent potential compiler warnings about unused lambda captures (such as io_context_.dispatch(
[this, self = self_ref_, status]() {
(void)self;
cleanup_cb_(this, !status.ok());
self_ref_.reset();
Contributor
Author
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. Not adding |
||
| }, | ||
|
|
@@ -65,7 +68,7 @@ void RayClientBidiReactor::OnDone(const grpc::Status &status) { | |
|
|
||
| void RayClientBidiReactor::DoDisconnect() { | ||
| io_context_.dispatch( | ||
| [this]() { | ||
| [this, self = self_ref_]() { | ||
| StartWritesDone(); | ||
| // Free the hold to allow OnDone being called. | ||
| RemoveHold(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,16 +109,20 @@ RayServerBidiReactor::RayServerBidiReactor( | |
| } | ||
|
|
||
| void RayServerBidiReactor::DoDisconnect() { | ||
| io_context_.dispatch([this]() { Finish(grpc::Status::OK); }, ""); | ||
| io_context_.dispatch([this, self = self_ref_]() { Finish(grpc::Status::OK); }, ""); | ||
| } | ||
|
|
||
| void RayServerBidiReactor::OnCancel() { | ||
| io_context_.dispatch([this]() { Disconnect(); }, ""); | ||
| io_context_.dispatch([this, self = self_ref_]() { Disconnect(); }, ""); | ||
| } | ||
|
|
||
| void RayServerBidiReactor::OnDone() { | ||
| // See RayClientBidiReactor::OnDone for why `self` is captured here. | ||
| io_context_.dispatch( | ||
| [this, cleanup_cb = cleanup_cb_, remote_node_id = GetRemoteNodeID()]() { | ||
| [this, | ||
| self = self_ref_, | ||
| cleanup_cb = cleanup_cb_, | ||
| remote_node_id = GetRemoteNodeID()]() { | ||
| cleanup_cb(this, false); | ||
| self_ref_.reset(); | ||
|
Comment on lines
121
to
127
Contributor
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. To prevent potential compiler warnings about unused lambda captures (such as io_context_.dispatch(
[this,
self = self_ref_,
cleanup_cb = cleanup_cb_,
remote_node_id = GetRemoteNodeID()]() {
(void)self;
cleanup_cb(this, false);
self_ref_.reset();
Contributor
Author
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. Not adding |
||
| }, | ||
|
|
||
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.
To prevent potential compiler warnings about unused lambda captures (such as
-Wunused-lambda-capturein Clang), it is recommended to explicitly cast the capturedselftovoidinside the lambda body. This also clearly documents that the capture is intended solely for lifetime management.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.
Not adding
(void)self;: clang's-Wunused-lambda-capturedoesn't fire for captures whose type has a non-trivial destructor likestd::shared_ptr, since holding the object alive is a legitimate use. The macOS build compiles with-Werror(.bazelrc) andbazel test //src/ray/ray_syncer/tests:ray_syncer_testbuilt and passed cleanly with clang. The comment inray_syncer_bidi_reactor.hdocuments that these captures exist for lifetime.