Skip to content

Commit

Permalink
Prevent watching unsuppoted channels
Browse files Browse the repository at this point in the history
  • Loading branch information
y-zeng committed Aug 23, 2017
1 parent 2411bac commit 6a6d618
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions include/grpc/grpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ GRPCAPI void grpc_channel_watch_connectivity_state(
grpc_channel *channel, grpc_connectivity_state last_observed_state,
gpr_timespec deadline, grpc_completion_queue *cq, void *tag);

/** Check whether a grpc channel support connectivity watcher */
GRPCAPI int grpc_channel_support_connectivity_watcher(grpc_channel *channel);

/** Create a call given a grpc_channel, in order to call 'method'. All
completions are sent to 'completion_queue'. 'method' and 'host' need only
live through the invocation of this function.
Expand Down
6 changes: 6 additions & 0 deletions src/core/ext/filters/client_channel/channel_connectivity.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ static void watcher_timer_init(grpc_exec_ctx *exec_ctx, void *arg,
gpr_free(wa);
}

int grpc_channel_support_connectivity_watcher(grpc_channel *channel) {
grpc_channel_element *client_channel_elem =
grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel));
return client_channel_elem->filter != &grpc_client_channel_filter ? 0 : 1;
}

void grpc_channel_watch_connectivity_state(
grpc_channel *channel, grpc_connectivity_state last_observed_state,
gpr_timespec deadline, grpc_completion_queue *cq, void *tag) {
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/client/channel_cc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Channel::Channel(const grpc::string& host, grpc_channel* channel)
host_(host),
c_channel_(channel) {
g_gli_initializer.summon();
if (host != "inproc") {
if (grpc_channel_support_connectivity_watcher(channel)) {
connectivity_watcher_->StartWatching();
}
}
Expand Down

0 comments on commit 6a6d618

Please sign in to comment.