This solution doesn't seem to work. Just tested with a server and client running locally. Killing the client process did not trigger a context.Done() call.
Here's the very basic code from the server: func (s *server) Listen(_ *service.ListenRequest, ls service.MyService_ListenServer) error { ctx := ls.Context() <-ctx.Done() glog.Errorln("Context done!") } Killing the client process does not cause the logs to show on my server. I deleted and re-fetched all my google.golang.org/grpc and golang.org/x/net/context dependencies today (Aug 30, 2017), so it surely can't be a problem with my dependencies being outdated (unless I'm missing something). It does not seem like listening on context.Done() is enough. Was the heartbeat solution ever implemented? On Tuesday, July 25, 2017 at 7:43:10 PM UTC+5, pawel...@gmail.com wrote: > > Just a notice for future readers. As today (2017.07.25) it's enough to > listen on context.Done(). > > func (p *XImpl) Listen(_ *empty.Empty, rec services.X_ListenServer) error { > c := make(chan *services.X, 16) > p.add(c) > defer p.remove(c) > ctx := rec.Context() > for { > select { > case v := <-c: > if err := rec.Send(v); err != nil { > return err > } > case <-ctx.Done(): > return nil > } > } > } > -- 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+unsubscr...@googlegroups.com. To post to this group, send email to grpc-io@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/8273cced-e1f4-407d-97e0-5e9936017603%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.