diff options
author | Craig Tiller <ctiller@google.com> | 2015-04-27 08:55:08 -0700 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2015-04-27 08:55:50 -0700 |
commit | 1fb99552b75e9b3fc1e391bc66049d1091128c5b (patch) | |
tree | c16aa91e6db897cc31474844ac3743d7cee892d4 | |
parent | 7305dc69e69fbd808f932a8b11c433bdcbe8a79d (diff) |
Fix early shutdown: await client context deletion before channel deletion
-rw-r--r-- | include/grpc++/client_context.h | 5 | ||||
-rw-r--r-- | src/cpp/client/channel.cc | 2 | ||||
-rw-r--r-- | src/cpp/client/channel.h | 1 |
3 files changed, 6 insertions, 2 deletions
diff --git a/include/grpc++/client_context.h b/include/grpc++/client_context.h index 19630c9b54..a58e9872e6 100644 --- a/include/grpc++/client_context.h +++ b/include/grpc++/client_context.h @@ -35,6 +35,7 @@ #define GRPCXX_CLIENT_CONTEXT_H #include <map> +#include <memory> #include <string> #include <grpc/support/log.h> @@ -126,9 +127,10 @@ class ClientContext { friend class ::grpc::ClientAsyncResponseReader; grpc_call* call() { return call_; } - void set_call(grpc_call* call) { + void set_call(grpc_call* call, const std::shared_ptr<ChannelInterface>& channel) { GPR_ASSERT(call_ == nullptr); call_ = call; + channel_ = channel; } grpc_completion_queue* cq() { return cq_; } @@ -137,6 +139,7 @@ class ClientContext { grpc::string authority() { return authority_; } bool initial_metadata_received_; + std::shared_ptr<ChannelInterface> channel_; grpc_call* call_; grpc_completion_queue* cq_; gpr_timespec deadline_; diff --git a/src/cpp/client/channel.cc b/src/cpp/client/channel.cc index ba8882278f..c541ddfb48 100644 --- a/src/cpp/client/channel.cc +++ b/src/cpp/client/channel.cc @@ -71,7 +71,7 @@ Call Channel::CreateCall(const RpcMethod& method, ClientContext* context, : context->authority().c_str(), context->raw_deadline()); GRPC_TIMER_MARK(CALL_CREATED, c_call); - context->set_call(c_call); + context->set_call(c_call, shared_from_this()); return Call(c_call, this, cq); } diff --git a/src/cpp/client/channel.h b/src/cpp/client/channel.h index cd239247c8..46009d20ba 100644 --- a/src/cpp/client/channel.h +++ b/src/cpp/client/channel.h @@ -51,6 +51,7 @@ class Credentials; class StreamContextInterface; class Channel GRPC_FINAL : public GrpcLibrary, + public std::enable_shared_from_this<Channel>, public ChannelInterface { public: Channel(const grpc::string& target, grpc_channel* c_channel); |