remove recover
This commit is contained in:
committed by
Jörn Friedrich Dreyer
parent
c597dfb917
commit
fbbcf3d833
@@ -392,28 +392,8 @@ func Start(ctx context.Context, o ...Option) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = rpc.Register(s); err != nil {
|
// register and run the runtime rpc server
|
||||||
if s != nil {
|
s.runRPCServer()
|
||||||
s.Log.Fatal().Err(err).Msg("could not register rpc service")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rpc.HandleHTTP()
|
|
||||||
|
|
||||||
l, err := net.Listen("tcp", net.JoinHostPort(s.cfg.Runtime.Host, s.cfg.Runtime.Port))
|
|
||||||
if err != nil {
|
|
||||||
s.Log.Fatal().Err(err).Msg("could not start listener")
|
|
||||||
}
|
|
||||||
srv := new(http.Server)
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
reason := strings.Builder{}
|
|
||||||
if _, err = net.Dial("tcp", net.JoinHostPort(s.cfg.Runtime.Host, s.cfg.Runtime.Port)); err != nil {
|
|
||||||
reason.WriteString("runtime address already in use")
|
|
||||||
}
|
|
||||||
fmt.Println(reason.String())
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// prepare the set of services to run
|
// prepare the set of services to run
|
||||||
s.generateRunSet(s.cfg)
|
s.generateRunSet(s.cfg)
|
||||||
@@ -437,14 +417,8 @@ func Start(ctx context.Context, o ...Option) error {
|
|||||||
// schedule services that are optional
|
// schedule services that are optional
|
||||||
scheduleServiceTokens(s, s.Additional)
|
scheduleServiceTokens(s, s.Additional)
|
||||||
|
|
||||||
go func() {
|
|
||||||
if err = srv.Serve(l); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
|
||||||
s.Log.Fatal().Err(err).Msg("could not start rpc server")
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// trapShutdownCtx will block on the context-done channel for interruptions.
|
// trapShutdownCtx will block on the context-done channel for interruptions.
|
||||||
trapShutdownCtx(s, srv, ctx)
|
trapShutdownCtx(s, ctx)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -512,20 +486,32 @@ func (s *Service) List(_ struct{}, reply *string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func trapShutdownCtx(s *Service, srv *http.Server, ctx context.Context) {
|
// register and run the runtime rpc server
|
||||||
<-ctx.Done()
|
func (s *Service) runRPCServer() {
|
||||||
wg := sync.WaitGroup{}
|
if err := rpc.Register(s); err != nil {
|
||||||
wg.Add(1)
|
if s != nil {
|
||||||
go func() {
|
s.Log.Fatal().Err(err).Msg("could not register rpc service")
|
||||||
defer wg.Done()
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), _defaultShutdownTimeoutDuration)
|
|
||||||
defer cancel()
|
|
||||||
if err := srv.Shutdown(ctx); err != nil {
|
|
||||||
s.Log.Error().Err(err).Msg("could not shutdown tcp listener")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.Log.Info().Msg("tcp listener shutdown")
|
}
|
||||||
|
rpc.HandleHTTP()
|
||||||
|
// run rpc server
|
||||||
|
srv := new(http.Server)
|
||||||
|
go func() {
|
||||||
|
l, err := net.Listen("tcp", net.JoinHostPort(s.cfg.Runtime.Host, s.cfg.Runtime.Port))
|
||||||
|
if err != nil {
|
||||||
|
s.Log.Fatal().Err(err).Msg("could not start listener")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = srv.Serve(l); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||||
|
s.Log.Fatal().Err(err).Msg("could not start rpc server")
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
func trapShutdownCtx(s *Service, ctx context.Context) {
|
||||||
|
<-ctx.Done()
|
||||||
|
wg := sync.WaitGroup{}
|
||||||
|
|
||||||
for sName := range s.serviceToken {
|
for sName := range s.serviceToken {
|
||||||
for i := range s.serviceToken[sName] {
|
for i := range s.serviceToken[sName] {
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
gr := runner.NewGroup(runner.Option())
|
gr := runner.NewGroup()
|
||||||
{
|
{
|
||||||
svc, err := service.NewAntivirus(cfg, logger, traceProvider)
|
svc, err := service.NewAntivirus(cfg, logger, traceProvider)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user