Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/ray/raylet_rpc_client/raylet_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,11 @@ void RayletClient::PinObjectIDs(
if (!generator_id.IsNil()) {
request.set_generator_id(generator_id.Binary());
}
auto self = shared_from_this();
pins_in_flight_++;
auto rpc_callback = [this, callback = std::move(callback)](
auto rpc_callback = [self, callback = std::move(callback)](
Status status, rpc::PinObjectIDsReply &&reply) {
pins_in_flight_--;
self->pins_in_flight_--;
callback(status, std::move(reply));
};
INVOKE_RETRYABLE_RPC_CALL(retryable_grpc_client_,
Expand Down
3 changes: 2 additions & 1 deletion src/ray/raylet_rpc_client/raylet_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ namespace rpc {

/// Raylet client is responsible for communication with raylet. It implements
/// [RayletClientInterface] and works on worker registration, lease management, etc.
class RayletClient : public RayletClientInterface {
class RayletClient : public RayletClientInterface,
public std::enable_shared_from_this<RayletClient> {
Copy link

Choose a reason for hiding this comment

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

Bug: Ensure shared_from_this compatibility with stack objects.

Adding std::enable_shared_from_this<RayletClient> breaks compatibility with stack-allocated RayletClient instances. The codebase has at least one stack-allocated instance at src/ray/core_worker/core_worker_process.cc:887. If PinObjectIDs is called on such an instance, shared_from_this() will throw std::bad_weak_ptr, causing a crash. While the current stack-allocated instance only calls GetSystemConfig, this creates a latent bug where future code changes could inadvertently call PinObjectIDs on stack-allocated instances.

Fix in Cursor Fix in Web

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll fix this as a follow up

public:
/// Connect to the raylet.
///
Expand Down