From 9ac6b96eeed2b717582345fb088b4ee4cc3dc557 Mon Sep 17 00:00:00 2001 From: Sebastian Tobie Date: Sat, 25 Mar 2023 09:41:46 +0100 Subject: [PATCH] server now waits on teardown sites --- http.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/http.go b/http.go index 02c1d7f..1bfcf95 100644 --- a/http.go +++ b/http.go @@ -188,11 +188,12 @@ func (s *Server) Use(m ...gin.HandlerFunc) { } // Stop Shuts the Server down -func (s *Server) Stop(ctx context.Context) { - log.Info().Err(s.http.Shutdown(ctx)).Msg("Server Shut down.") - for _, s := range s.sites { +func (server *Server) Stop(ctx context.Context) { + log.Info().Err(server.http.Shutdown(ctx)).Msg("Server Shut down.") + for _, s := range server.sites { if ts, ok := s.(TeardownSite); ok { ts.Teardown() + server.routines.Done() } } } @@ -304,6 +305,10 @@ func (s *Server) Setup() { log.Error().Err(err).Msgf("Failed to setup site with config %s", cfg) } } + if _, ok := site.(TeardownSite); ok { + log.Trace().Msg("Added teardownsite to the sg") + s.routines.Add(1) + } } for _, m := range s.advmiddleware { if psm, ok := m.(middleware.PostSetupMiddleware); ok {