in grpc-xds/greeter-go/pkg/server/server.go [166:187]
func addServerStopBehavior(ctx context.Context, logger logr.Logger, servingGRPCServer grpcserver, healthGRPCServer grpcserver, healthServer *health.Server) {
go func() {
<-ctx.Done()
healthServer.SetServingStatus("", healthpb.HealthCheckResponse_NOT_SERVING)
healthServer.SetServingStatus(helloworldpb.Greeter_ServiceDesc.ServiceName, healthpb.HealthCheckResponse_NOT_SERVING)
stopped := make(chan struct{})
go func() {
logger.Info("Attempting to gracefully stop the gRPC server")
servingGRPCServer.GracefulStop()
close(stopped)
}()
timer := time.NewTimer(5 * time.Second)
select {
case <-timer.C:
logger.Info("Stopping the gRPC server immediately")
servingGRPCServer.Stop()
healthGRPCServer.Stop()
case <-stopped:
timer.Stop()
}
}()
}