Server side connection management

259 views
Skip to first unread message

Arpit Baldeva

unread,
Sep 12, 2017, 3:23:48 PM9/12/17
to grpc.io
Hi,

 
It looks like the connections are not considered idle if they have outstanding rpcs. That would mean it includes server streaming rpcs as well, right? A common use case for server streaming rpcs is to allow for a Server to Client Notification system. This means application need to do "no rpc from client in some duration" detection as well in this scenario and finish streaming rpc before grpc library can run the network layer clean up on it's end?

Thanks. 

Spencer Fang

unread,
Sep 13, 2017, 1:18:43 PM9/13/17
to Arpit Baldeva, grpc.io
Your reading is correct, the idle manager checks for the case where there are no active RPCs (including long lived streaming RPCs). The StreamTracer provides a way to check the last time a message was sent or received on a per RPC basis, but unfortunately there's no connection level aggregation at the moment.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscribe@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/91a74931-3580-4e9f-a9d2-1bcd3b743818%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Spencer Fang

rav...@gmail.com

unread,
Jan 5, 2018, 8:54:12 PM1/5/18
to grpc.io
Hi Arpit,

Did you get this working?

I am looking for similar scenario where I have to keep the list of client session information on the server side.
Based on someother event, I have to determine which client shall handle this event and send message to that specific client.

I don't seem to find these details from Context ... any help would be great

Arpit Baldeva

unread,
Jan 6, 2018, 4:42:31 PM1/6/18
to rav...@gmail.com, grpc.io
My question was mainly around how to make sure the client network connection is cleaned up. I did end up with a simple mechanism to detect session inactivity and terminate you streaming rpcs at that point. If I get your question right, you just need to implement your notifications as a server streaming rpc per client/session.

--
You received this message because you are subscribed to a topic in the Google Groups "grpc.io" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/grpc-io/g9oittuh_6c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to grpc-io+unsubscribe@googlegroups.com.

To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.

Ravi Jonnadula

unread,
Jan 8, 2018, 3:39:06 PM1/8/18
to Arpit Baldeva, grpc.io
In my case, once he client initiates first RPC message, I wanted to keep the communication channel open between the server-clients.
The sever shall be able to send message to a specific client at some later point of time through this RPC channel.
For that, I shall be able to maintain a list/map of clients active based on the context information available.
With the information available from context.Conetext() I was not able to distinguish different clients from the different/same remote. 

Arpit Baldeva

unread,
Jan 8, 2018, 4:32:40 PM1/8/18
to grpc.io
You can do this at your application level. Say your first rpc is "login" (or whatever you want it to be). You can create a "session" object in your application and return it some sort of "session-key" in the metadata. After that, your client must send that "session-key" in it's client context in future rpcs and one of that could be your server streaming notification rpc. 


On Monday, January 8, 2018 at 12:39:06 PM UTC-8, Ravi Jonnadula wrote:
In my case, once he client initiates first RPC message, I wanted to keep the communication channel open between the server-clients.
The sever shall be able to send message to a specific client at some later point of time through this RPC channel.
For that, I shall be able to maintain a list/map of clients active based on the context information available.
With the information available from context.Conetext() I was not able to distinguish different clients from the different/same remote. 

On Sat, Jan 6, 2018 at 1:42 PM Arpit Baldeva <abal...@gmail.com> wrote:
My question was mainly around how to make sure the client network connection is cleaned up. I did end up with a simple mechanism to detect session inactivity and terminate you streaming rpcs at that point. If I get your question right, you just need to implement your notifications as a server streaming rpc per client/session.
On Fri, Jan 5, 2018 at 5:54 PM, <rav...@gmail.com> wrote:
Hi Arpit,

Did you get this working?

I am looking for similar scenario where I have to keep the list of client session information on the server side.
Based on someother event, I have to determine which client shall handle this event and send message to that specific client.

I don't seem to find these details from Context ... any help would be great


On Tuesday, September 12, 2017 at 12:23:48 PM UTC-7, Arpit Baldeva wrote:
Hi,

 
It looks like the connections are not considered idle if they have outstanding rpcs. That would mean it includes server streaming rpcs as well, right? A common use case for server streaming rpcs is to allow for a Server to Client Notification system. This means application need to do "no rpc from client in some duration" detection as well in this scenario and finish streaming rpc before grpc library can run the network layer clean up on it's end?

Thanks. 

--
You received this message because you are subscribed to a topic in the Google Groups "grpc.io" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/grpc-io/g9oittuh_6c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to grpc-io+u...@googlegroups.com.

To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.

Ravi Jonnadula

unread,
Jan 8, 2018, 5:03:45 PM1/8/18
to Arpit Baldeva, grpc.io
Is there any option to get the client source IP/port information from the context (without needing to explicitly encode it from the client side metadata)?

thanks.

To unsubscribe from this group and all its topics, send an email to grpc-io+unsubscribe@googlegroups.com.

To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.

Spencer Fang

unread,
Jan 8, 2018, 5:19:14 PM1/8/18
to Ravi Jonnadula, Arpit Baldeva, grpc.io
Ravi:
The client source IP/port information is present in the Attributes object when the ServerCall is started, under the Metadata.Key io.grpc.Grpc.TRANSPORT_ATTR_REMOTE_ADDR. You can stash away the ServerCall when you server handler starts, or as a part of a ServerInterceptor. But keep in mind that ServerCall is not synchronized, so if you ever share it between threads you need to perform your own synchronization.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscribe@googlegroups.com.

To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.

For more options, visit https://groups.google.com/d/optout.



--
Spencer Fang

Spencer Fang

unread,
Jan 8, 2018, 5:19:47 PM1/8/18
to Ravi Jonnadula, Arpit Baldeva, grpc.io
Correction: io.grpc.Grpc.TRANSPORT_ATTR_REMOTE_ADDR is an Attributes.Key
--
Spencer Fang

Ravi Jonnadula

unread,
Jan 8, 2018, 7:17:49 PM1/8/18
to Spencer Fang, Arpit Baldeva, grpc.io
Hi Spencer,

Thanks for your response. this is exactly what I 'm looking for.
However, looks like this is available only in grpc-Java ... can't find it in grpc-go ...

Any equivalent in grpc-go?

thanks.

Spencer Fang

unread,
Jan 8, 2018, 7:19:33 PM1/8/18
to Ravi Jonnadula, Menghan Li, Arpit Baldeva, grpc.io
+meng...@google.com, who works on grpc-go
--
Spencer Fang

Menghan Li

unread,
Jan 8, 2018, 7:58:29 PM1/8/18
to grpc.io
Ravi,

In go, the client address is part of the peer struct in the RPC context (https://godoc.org/google.golang.org/grpc/peer#Peer).

Use https://godoc.org/google.golang.org/grpc/peer#FromContext to get peer out from the context.

Thanks,
Menghan

Arpit Baldeva

unread,
Jan 8, 2018, 9:29:54 PM1/8/18
to Menghan Li, grpc.io
Client IP is not a reliable way to keep track of client. For example, you could have many clients sitting behind a proxy and they will share the ip address. I only use it for logging purpose. So depends on your use case.

--
You received this message because you are subscribed to a topic in the Google Groups "grpc.io" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/grpc-io/g9oittuh_6c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to grpc-io+unsubscribe@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.

Ravi Jonnadula

unread,
Jan 9, 2018, 3:51:34 PM1/9/18
to Arpit Baldeva, Menghan Li, grpc.io
Good point Arpit, agreed, when there is a proxy.

Thanks Menghan, et all for your help.



Reply all
Reply to author
Forward
0 new messages