Is gRPC golang server able to catch the client disconnecting event and do something accordingly?

84 views
Skip to first unread message

yz

unread,
Jan 23, 2018, 6:44:35 AM1/23/18
to grpc.io
We are implementing authentication on gRPC  Golang server. When a client connect to the server, it needs to send the token to the server to authenticate itself, and the server will save the auth info. When the client disconnect, the server should remove the auth info. But I could not find a way to be notified when the connection is closed. Does this kind of transportation supported on gRPC golang server?

Eric Anderson

unread,
Jan 25, 2018, 4:57:36 PM1/25/18
to yz, grpc.io
On Tue, Jan 23, 2018 at 3:44 AM, 'yz' via grpc.io <grp...@googlegroups.com> wrote:
We are implementing authentication on gRPC  Golang server. When a client connect to the server, it needs to send the token to the server to authenticate itself, and the server will save the auth info. When the client disconnect, the server should remove the auth info. But I could not find a way to be notified when the connection is closed. Does this kind of transportation supported on gRPC golang server?

I strongly discourage this sort of design. I'd suggest the client provide some authentication token in each RPC (this is inexpensive on-the-wire with HPACK) and optimize using a cache on server-side if necessary.

gRPC is free to recreate connections at any point, or use multiple connections. Also such a service would not work through an L7 load balancer, although I admit many people don't care about that case.

yz

unread,
Jan 25, 2018, 9:45:11 PM1/25/18
to grpc.io
Thanks Eric. I get your point that the gRPC  client could make multiple connections during a session. But if we use a local cache on the server, the tricky problem then becomes when the cache item should expire? 
Reply all
Reply to author
Forward
0 new messages