Fix crash because of the reference to deleted variable in grpc server call (#5158)

This commit is contained in:
Joey Jiang
2019-07-10 14:06:21 +08:00
committed by Hao Chen
parent 2b7b7c7547
commit e55c8ca165
+7 -4
View File
@@ -142,12 +142,15 @@ class ServerCallImpl : public ServerCall {
request_, &reply_,
[this](Status status, std::function<void()> success,
std::function<void()> 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);
});
}