From a9de99b04a29e0702382842711c8d006ec1294c9 Mon Sep 17 00:00:00 2001 From: mountain Date: Mon, 10 Jul 2023 17:15:59 +0900 Subject: [PATCH] =?UTF-8?q?healthCheckHandler=20=EB=A1=9C=EA=B7=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/server.go b/server.go index d38d198..27c5da9 100644 --- a/server.go +++ b/server.go @@ -73,7 +73,10 @@ func healthCheckHandler(w http.ResponseWriter, r *http.Request) { // 한번이라도 들어오면 lb에 붙어있다는 뜻 if t := atomic.AddInt64(&healthcheckcounter, 1); t < 0 { + logger.Println("healthCheckHandler return StatusServiceUnavailable :", t) w.WriteHeader(http.StatusServiceUnavailable) + } else { + logger.Println("healthCheckHandler return StatusOK :", t) } } @@ -127,11 +130,18 @@ func (server *Server) shutdown() { signal.Stop(server.interrupt) - if atomic.LoadInt64(&healthcheckcounter) > 0 { - atomic.StoreInt64(&healthcheckcounter, math.MinInt64) - for atomic.LoadInt64(&healthcheckcounter)-math.MinInt64 == 0 { + if t := atomic.LoadInt64(&healthcheckcounter); t > 0 { + logger.Println("http server shutdown. healthcheckcounter :", t) + + t = math.MinInt64 + atomic.StoreInt64(&healthcheckcounter, t) + for ; t-math.MinInt64 > 0; t = atomic.LoadInt64(&healthcheckcounter) { + logger.Println(" waiting for healthcheckcounter increase y lb", t-math.MinInt64) time.Sleep(100 * time.Millisecond) } + logger.Println("http server shutdown. healthcheck completed") + } else { + logger.Println("http server shutdown. no lb") } if server.httpserver != nil {