From e55c8ca16594eb946d61169392c088cd7ea75adb Mon Sep 17 00:00:00 2001 From: Joey Jiang <452084368@qq.com> Date: Wed, 10 Jul 2019 14:06:21 +0800 Subject: [PATCH] Fix crash because of the reference to deleted variable in grpc server call (#5158) --- src/ray/rpc/server_call.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/ray/rpc/server_call.h b/src/ray/rpc/server_call.h index 19964c5bd..b2afee0b1 100644 --- a/src/ray/rpc/server_call.h +++ b/src/ray/rpc/server_call.h @@ -142,12 +142,15 @@ class ServerCallImpl : public ServerCall { request_, &reply_, [this](Status status, std::function success, std::function failure) { - // When the handler is done with the - // request, tell gRPC to finish this - // request. - SendReply(status); + // These two callbacks must be set before `SendReply`, because `SendReply` + // is aysnc and this `ServerCall` might be deleted right after `SendReply`. send_reply_success_callback_ = std::move(success); send_reply_failure_callback_ = std::move(failure); + + // When the handler is done with the request, tell gRPC to finish this request. + // Must send reply at the bottom of this callback, once we invoke this funciton, + // this server call might be deleted + SendReply(status); }); }