func addServerStopBehavior()

in grpc-xds/control-plane-go/pkg/server/server.go [287:307]


func addServerStopBehavior(ctx context.Context, logger logr.Logger, servingGRPCServer *grpc.Server, healthGRPCServer *grpc.Server, healthServer *health.Server) {
	go func() {
		<-ctx.Done()
		healthServer.SetServingStatus("", healthpb.HealthCheckResponse_NOT_SERVING)
		stopped := make(chan struct{})
		go func() {
			logger.Info("Attempting to gracefully stop the xDS management server")
			servingGRPCServer.GracefulStop()
			close(stopped)
		}()
		t := time.NewTimer(5 * time.Second)
		select {
		case <-t.C:
			logger.Info("Stopping the xDS management server immediately")
			servingGRPCServer.Stop()
			healthGRPCServer.Stop()
		case <-stopped:
			t.Stop()
		}
	}()
}