MCPcopy
hub / github.com/grafana/dskit / Run

Method Run

server/server.go:651–693  ·  server/server.go::Server.Run

Run the server; blocks until SIGTERM (if signal handling is enabled), an error is received, or Stop() is called.

()

Source from the content-addressed store, hash-verified

649
650// Run the server; blocks until SIGTERM (if signal handling is enabled), an error is received, or Stop() is called.
651func (s *Server) Run() error {
652 errChan := make(chan error, 1)
653
654 // Wait for a signal
655 go func() {
656 s.handler.Loop()
657 select {
658 case errChan <- nil:
659 default:
660 }
661 }()
662
663 go func() {
664 var err error
665 if s.HTTPServer.TLSConfig == nil {
666 err = s.HTTPServer.Serve(s.httpListener)
667 } else {
668 err = s.HTTPServer.ServeTLS(s.httpListener, s.cfg.HTTPTLSConfig.TLSCertPath, s.cfg.HTTPTLSConfig.TLSKeyPath)
669 }
670 if err == http.ErrServerClosed {
671 err = nil
672 }
673
674 select {
675 case errChan <- err:
676 default:
677 }
678 }()
679
680 serverOptions := make([]httpgrpc_server.Option, 0, 1)
681 if s.cfg.ReportHTTP4XXCodesInInstrumentationLabel {
682 serverOptions = append(serverOptions, httpgrpc_server.WithReturn4XXErrors)
683 }
684 // Setup gRPC server for HTTP over gRPC, ensure we don't double-count the middleware
685 httpgrpc.RegisterHTTPServer(s.GRPC, httpgrpc_server.NewServer(s.HTTP, serverOptions...))
686
687 go func() {
688 err := s.GRPC.Serve(s.grpcListener)
689 handleGRPCError(err, errChan)
690 }()
691
692 return <-errChan
693}
694
695// handleGRPCError consolidates GRPC Server error handling by sending
696// any error to errChan except for grpc.ErrServerStopped which is ignored.

Callers 15

TestMemcachedClient_SetFunction · 0.80
TestMemcachedClient_AddFunction · 0.80
TestVersionedFunction · 0.80
TestSnappyCacheFunction · 0.80
TestErrorFunction · 0.80

Calls 3

RegisterHTTPServerFunction · 0.92
handleGRPCErrorFunction · 0.85
LoopMethod · 0.65

Tested by 15

TestMemcachedClient_SetFunction · 0.64
TestMemcachedClient_AddFunction · 0.64
TestVersionedFunction · 0.64
TestSnappyCacheFunction · 0.64
TestErrorFunction · 0.64