From 70d30ec662657bcb6fd0f6e5e0f09db44adfc809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kowal?= Date: Fri, 19 Apr 2024 19:26:15 +0200 Subject: [PATCH] Refactor --- internal/proxy/server.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/proxy/server.go b/internal/proxy/server.go index 6d5c74b..80af86a 100644 --- a/internal/proxy/server.go +++ b/internal/proxy/server.go @@ -120,9 +120,11 @@ func (s *Server) Start() error { } // Implementing graceful shutdown - if an interrupt signal is received, stop listening on the port - idleConnsClosed := make(chan struct{}) + idleConnClosedChan := make(chan struct{}) go func() { + defer close(idleConnClosedChan) + sigint := make(chan os.Signal, 1) signal.Notify(sigint, os.Interrupt) <-sigint @@ -133,13 +135,12 @@ func (s *Server) Start() error { // Error from closing listener(s), or context timeout: log.Printf("HTTP server Shutdown: %v", err) } - close(idleConnsClosed) }() if err := server.Serve(tcpListener); err != nil && !errors.Is(err, http.ErrServerClosed) { return fmt.Errorf("server serve: %w", err) } - <-idleConnsClosed + <-idleConnClosedChan return nil }