From 8ec82331cc8f627a33aa200035815f907662e861 Mon Sep 17 00:00:00 2001 From: Ralf Haferkamp Date: Tue, 28 Apr 2026 12:32:04 +0200 Subject: [PATCH] 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 (cherry picked from commit 7a149787d013cb7d9ee259cd385ce4b5991e8fed) --- opencloud/pkg/runtime/service/service.go | 2 +- services/nats/pkg/command/server.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/opencloud/pkg/runtime/service/service.go b/opencloud/pkg/runtime/service/service.go index a02bab58cf..3b2b6ace56 100644 --- a/opencloud/pkg/runtime/service/service.go +++ b/opencloud/pkg/runtime/service/service.go @@ -439,7 +439,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) diff --git a/services/nats/pkg/command/server.go b/services/nats/pkg/command/server.go index b47a93e5b7..ed80660383 100644 --- a/services/nats/pkg/command/server.go +++ b/services/nats/pkg/command/server.go @@ -91,7 +91,9 @@ func Server(cfg *config.Config) *cli.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)