fix: avoid suture.Supervisor being shutdown early

Previously the Supervisor was shutdonw as soon as the main context was
canceled. Which cause the managed services to fail during shutdown (in
"trapShutdownCtx()") as the Supervisor was gone already.

We now pass a separate Context to Supervisor.ServeBackground() to avoid
this.

Fixes: #2282
This commit is contained in:
Ralf Haferkamp
2026-04-28 12:32:04 +02:00
committed by Ralf Haferkamp
parent c7eeb899d6
commit 7a149787d0
2 changed files with 3 additions and 1 deletions

View File

@@ -433,7 +433,7 @@ func Start(ctx context.Context, o ...Option) error {
// go supervisor.Serve()
// because that will briefly create a race condition as it starts up, if you try to .Add() services immediately afterward.
// https://pkg.go.dev/github.com/thejerf/suture/v4@v4.0.0#Supervisor
go s.Supervisor.ServeBackground(ctx)
go s.Supervisor.ServeBackground(context.Background())
for i, service := range s.Services {
scheduleServiceTokens(s, service)

View File

@@ -91,7 +91,9 @@ func Server(cfg *config.Config) *cobra.Command {
gr.Add(runner.New(cfg.Service.Name+".svc", func() error {
return natsServer.ListenAndServe()
}, func() {
logger.Info().Msg("Gracefully shutting down the NATS server...")
natsServer.Shutdown()
logger.Info().Msg("NATS server shutdown")
}))
grResults := gr.Run(ctx)