Propagate Cancellation To Beacon Node Server (#8512)

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Nishant Das 2021-02-25 01:10:25 +08:00 committed by GitHub
parent 6ee290a9af
commit 08b938982b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -57,7 +57,12 @@ func (s *Server) GetVersion(ctx context.Context, _ *ptypes.Empty) (*pb.VersionRe
// StreamBeaconLogs from the beacon node via a gRPC server-side stream.
func (s *Server) StreamBeaconLogs(req *ptypes.Empty, stream pb.Health_StreamBeaconLogsServer) error {
client, err := s.beaconNodeHealthClient.StreamBeaconLogs(s.ctx, req)
// Wrap service context with a cancel in order to propagate the exiting of
// this method properly to the beacon node server.
ctx, cancel := context.WithCancel(s.ctx)
defer cancel()
client, err := s.beaconNodeHealthClient.StreamBeaconLogs(ctx, req)
if err != nil {
return err
}
@ -67,6 +72,8 @@ func (s *Server) StreamBeaconLogs(req *ptypes.Empty, stream pb.Health_StreamBeac
return status.Error(codes.Canceled, "Context canceled")
case <-stream.Context().Done():
return status.Error(codes.Canceled, "Context canceled")
case <-client.Context().Done():
return status.Error(codes.Canceled, "Context canceled")
default:
resp, err := client.Recv()
if err != nil {