How to retrieve hostname from channel interface?

749 views
Skip to first unread message

Norman Link

unread,
Jul 4, 2018, 8:19:31 AM7/4/18
to grpc.io
Hi everyone,

Is it possible to retrieve the hostname from an already constructed channel, i.e. a `ChannelInterface`?

The reason is this:
I have a client abstraction class that gets passed a `ChannelInterface` at construction time. For unit testing, I will provide it with an in-process channel.
This client also checks the connection status by creating a `NotifyOnStateChange` task on the completion queue. This is important for "real" channels, but since an in-process channel is always connected, it does not really make sense there. However, since I cannot check how this channel was actually constructed, I always do it. My unit test log is then full of messages like

 grpc_channel_check_connectivity_state called on something that is not a client channel, but 'connected'

I understand that the hostname for a local channel is `inproc`, but there are no means to query it afterwards. If there were, I would be able to check it before creating the task on the task queue.

Would it make sense to add this to the interface? I imagine something like:

virtual grpc::string ChannelInterface::GetHost() const = 0;

Kind regards,
Norman

ncte...@google.com

unread,
Jul 11, 2018, 5:12:34 PM7/11/18
to grpc.io
I see no reason why this can't exist in our C++ ChannelInterface API. Vijay, API gatekeeper, any reason against?

Feel free to send me a PR in the meantime

Eric Anderson

unread,
Jul 11, 2018, 6:25:36 PM7/11/18
to Noah Eisen, grpc-io
On Wed, Jul 11, 2018 at 2:12 PM ncteisen via grpc.io <grp...@googlegroups.com> wrote:
On Wednesday, July 4, 2018 at 5:19:31 AM UTC-7, Norman Link wrote:
I understand that the hostname for a local channel is `inproc`, but there are no means to query it afterwards. If there were, I would be able to check it before creating the task on the task queue.

Would it make sense to add this to the interface? I imagine something like:

virtual grpc::string ChannelInterface::GetHost() const = 0;

I'm a bit worried about doing that, as we still need to align this sort of thing cross-language. Abusing the host to detect inprocess could prevent us from aligning. For example, today grpc-java uses "localhost" here.

I'll also mention that in Java you can use the channel state API, as the inproc server may not be started and so the client would need to reconnect once it is started. It's actually pretty nice that you can use this sort of API. There's more discussion here to get things looking the same cross-language, but I believe this is likely to be available at some point for C.

Norman Link

unread,
Jul 18, 2018, 7:17:17 AM7/18/18
to grpc.io
As you suggested, I created a pull request here:

Kind regards,
Norman
Reply all
Reply to author
Forward
0 new messages