From 2c95250f725322115021958232e1d27ef3244cd6 Mon Sep 17 00:00:00 2001 From: Marina Biryukova Date: Wed, 27 Dec 2023 13:33:09 +0300 Subject: [PATCH] [#99] Fix possibility of panic during SIGHUP Signed-off-by: Marina Biryukova --- CHANGELOG.md | 1 + internal/logs/logs.go | 1 + metrics/service.go | 5 ++++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23878ca..79ef8d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ This document outlines major changes between releases. ## [Unreleased] ### Fixed +- Fix possibility of panic during SIGHUP (#99) ### Added - Support client side object cut (#70) diff --git a/internal/logs/logs.go b/internal/logs/logs.go index 9d464c3..c75e91f 100644 --- a/internal/logs/logs.go +++ b/internal/logs/logs.go @@ -20,6 +20,7 @@ const ( ServiceHasntStartedSinceItsDisabled = "service hasn't started since it's disabled" // Info in ../../metrics/service.go ShuttingDownService = "shutting down service" // Info in ../../metrics/service.go CantShutDownService = "can't shut down service" // Panic in ../../metrics/service.go + CantGracefullyShutDownService = "can't gracefully shut down service, force stop" // Error in ../../metrics/service.go IgnorePartEmptyFormName = "ignore part, empty form name" // Debug in ../../uploader/upload.go IgnorePartEmptyFilename = "ignore part, empty filename" // Debug in ../../uploader/upload.go CloseTemporaryMultipartFormFile = "close temporary multipart/form file" // Debug in ../../uploader/upload.go diff --git a/metrics/service.go b/metrics/service.go index c025f06..dea5ac0 100644 --- a/metrics/service.go +++ b/metrics/service.go @@ -40,6 +40,9 @@ func (ms *Service) ShutDown(ctx context.Context) { ms.log.Info(logs.ShuttingDownService, zap.String("endpoint", ms.Addr)) err := ms.Shutdown(ctx) if err != nil { - ms.log.Panic(logs.CantShutDownService) + ms.log.Error(logs.CantGracefullyShutDownService, zap.Error(err)) + if err = ms.Close(); err != nil { + ms.log.Panic(logs.CantShutDownService, zap.Error(err)) + } } }