diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index afa6e6657c1..83cd6bd70a9 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -6,7 +6,6 @@ import ( "net" "net/http" "net/rpc" - "os" "sort" "strings" "time" @@ -515,7 +514,7 @@ func trap(s *Service, ctx context.Context) { } } s.Log.Debug().Str("service", "runtime service").Msgf("terminating with signal: %v", s) - os.Exit(0) + //os.Exit(0) // this seems to cause an early exit that prevents services from shitting down properly } // pingNats will attempt to connect to nats, blocking until a connection is established diff --git a/services/app-registry/pkg/command/server.go b/services/app-registry/pkg/command/server.go index 14f4ab277fc..0322d6c0eb6 100644 --- a/services/app-registry/pkg/command/server.go +++ b/services/app-registry/pkg/command/server.go @@ -41,6 +41,13 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() + gr.Add(func() error { + <-ctx.Done() + cancel() + return nil + }, func(err error) { + }) + gr.Add(func() error { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg := revaconfig.AppRegistryConfigFromStruct(cfg, logger) diff --git a/services/frontend/pkg/command/events.go b/services/frontend/pkg/command/events.go index 83ca24c7cac..f80055da461 100644 --- a/services/frontend/pkg/command/events.go +++ b/services/frontend/pkg/command/events.go @@ -94,7 +94,7 @@ func ListenForEvents(ctx context.Context, cfg *config.Config, l log.Logger) erro } case <-ctx.Done(): l.Info().Msg("context cancelled") - return ctx.Err() + return nil } } } diff --git a/services/nats/pkg/command/server.go b/services/nats/pkg/command/server.go index 2412c43f637..6ad8a693174 100644 --- a/services/nats/pkg/command/server.go +++ b/services/nats/pkg/command/server.go @@ -4,6 +4,7 @@ import ( "context" "crypto/tls" "fmt" + "time" "github.com/oklog/run" @@ -100,6 +101,13 @@ func Server(cfg *config.Config) *cli.Command { }, func(err error) { if err == nil { + logger.Info(). + Str("transport", "nats"). + Str("server", cfg.Service.Name). + Msg("letting other services deregister") + + time.Sleep(3 * time.Second) + logger.Info(). Str("transport", "nats"). Str("server", cfg.Service.Name).