Channels in same process use the same port

34 views
Skip to first unread message

Sam

unread,
Mar 11, 2019, 8:06:22 AM3/11/19
to grpc.io
Hi all,

I'm new to network programming in general and gRPC, so sorry if this is a daft question...

I'm using the C# implementation of gRPC and noticed something: I create a server project (lets say with one service method) and a client project. When I create more than one Channel to the server in the client project and call the rpc method that's on the server, it seems that the ServerCallContext.Peer property shows that the port use by both channels are the same. 

To clarify, I have the following setup:
- one server with one service method, always listening.
- a client project that creates 2 channels to the server.

When I print the ServerCallContext.Peer :
peer is ipv6:[::1]:51048 // print from the first channels call
peer is ipv6:[::1]:51048 // print from the second channels call

The port is the same. I tried executing the project twice (adding a for loop + a delay to have both working parallel) to see what happens, it seems that the port changes. I assume it's because they are from two different processes.

Anyway I'm just curious about why this is happening and what documentation I should read to understand this (if any exists ofc) ? 

Sam

Jan Tattermusch

unread,
Mar 18, 2019, 8:30:24 AM3/18/19
to grpc.io
What you're seeing is called "subchannel sharing". Basically if two channels on the client side have exactly the same targets and all the options are the same, C core can decide to use the same TCP/IP connection for both channels. This is probably what's happening in your case and it seems that things are working as expected and there's nothing to worry about.

Sam

unread,
Mar 19, 2019, 8:28:41 AM3/19/19
to grpc.io
Right, good to know ! 
Thanks for answering.
Reply all
Reply to author
Forward
0 new messages