From bbb9d200ce03272c73130c68d3ea2b7adba660c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D1=8F=D0=B1=D0=BE=D0=B2=20=D0=92=D0=BB=D0=B0=D0=B4?= =?UTF-8?q?=D0=B8=D1=81=D0=BB=D0=B0=D0=B2=20=D0=9E=D0=BB=D0=B5=D0=B3=D0=BE?= =?UTF-8?q?=D0=B2=D0=B8=D1=87?= Date: Mon, 8 Feb 2021 12:11:41 +0300 Subject: [PATCH] fixed graceful shutdown --- main.go | 4 ++-- service/socket.go | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index d660117..2ad3ff4 100644 --- a/main.go +++ b/main.go @@ -53,9 +53,9 @@ func socketConfiguration(cfg interface{}) structure.SocketConfiguration { } } -func onShutdown(_ context.Context, _ os.Signal) { +func onShutdown(ctx context.Context, _ os.Signal) { + service.SessionManager.ShutdownSocket(ctx) backend.StopGrpcServer() - service.SessionManager.ShutdownSocket() closeListeners(wsLn, grpcLn) } diff --git a/service/socket.go b/service/socket.go index ff087d5..768cd9d 100644 --- a/service/socket.go +++ b/service/socket.go @@ -6,7 +6,6 @@ import ( "net" "net/http" "sync" - "time" etp "github.com/integration-system/isp-etp-go/v2" "github.com/integration-system/isp-lib/v2/structure" @@ -207,10 +206,7 @@ func (s *sessionManager) InitWebSocket(ln net.Listener) { }() } -func (s *sessionManager) ShutdownSocket() { - ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Second) - defer cancel() - +func (s *sessionManager) ShutdownSocket(ctx context.Context) { if err := s.httpServer.Shutdown(ctx); err != nil { log.Errorf(44, "Unable to shutdown http server. err: %v", err) }