diff --git a/cmd/scality-cosi-driver/main.go b/cmd/scality-cosi-driver/main.go index edc930fb..bb443bc0 100644 --- a/cmd/scality-cosi-driver/main.go +++ b/cmd/scality-cosi-driver/main.go @@ -36,13 +36,16 @@ func main() { go func() { sig := <-sigs klog.InfoS("Signal received", "type", sig) - cancel() // Trigger context cancellation + cancel() + + klog.InfoS("Initiating graceful shutdown, repeat signal to force shutdown") select { - case <-ctx.Done(): - klog.InfoS("Scality COSI driver shutdown initiated successfully, context canceled") + case sig = <-sigs: + klog.ErrorS(nil, "Force shutdown due to repeated signal", "type", sig) + os.Exit(1) case <-time.After(30 * time.Second): - klog.ErrorS(nil, "Scality COSI driver graceful shutdown timed out, forcing application exit after 30 seconds") + klog.ErrorS(nil, "Force shutdown due to timeout", "timeout", 30*time.Second) os.Exit(1) } }() @@ -50,5 +53,6 @@ func main() { // Call the run function (defined in cmd.go) if err := run(ctx); err != nil { klog.ErrorS(err, "Scality COSI driver encountered an error, shutting down") + os.Exit(1) } } diff --git a/pkg/grpcfactory/server_test.go b/pkg/grpcfactory/server_test.go index 5b584e32..23c501e5 100644 --- a/pkg/grpcfactory/server_test.go +++ b/pkg/grpcfactory/server_test.go @@ -11,6 +11,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/prometheus/client_golang/prometheus" "github.com/scality/cosi-driver/pkg/grpcfactory" cosi "sigs.k8s.io/container-object-storage-interface-spec" ) @@ -59,7 +60,7 @@ var _ = Describe("gRPC Factory Server", Ordered, func() { Expect(server).NotTo(BeNil()) go func() { - err := server.Run(ctx) + err := server.Run(ctx, prometheus.NewRegistry()) if errors.Is(err, context.Canceled) { return // Expected when the context is canceled } @@ -81,7 +82,7 @@ var _ = Describe("gRPC Factory Server", Ordered, func() { Expect(server2).NotTo(BeNil()) // Run the second server and expect it to fail - err = server2.Run(ctx) + err = server2.Run(ctx, prometheus.NewRegistry()) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("address already in use")) }, SpecTimeout(1*time.Second)) @@ -94,7 +95,7 @@ var _ = Describe("gRPC Factory Server", Ordered, func() { Expect(server).NotTo(BeNil()) // Wait for server.Run to return an error - err = server.Run(ctx) + err = server.Run(ctx, prometheus.NewRegistry()) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("unsupported scheme: expected 'unix'")) }, SpecTimeout(1*time.Second))