diff --git a/router/router.go b/router/router.go index 60a33f10..1f0bb086 100644 --- a/router/router.go +++ b/router/router.go @@ -7,6 +7,7 @@ import ( "os" "os/signal" "path" + "time" "github.com/gin-contrib/cors" "github.com/gin-contrib/sse" @@ -101,7 +102,10 @@ func (r *Router) Stop() { instanceService.StopAll() - err := r.server.Shutdown(context.Background()) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) + defer cancel() + + err := r.server.Shutdown(ctx) if err != nil { log.Error(err) return @@ -123,6 +127,10 @@ func (r *Router) handleSignals() { <-c log.Info("shutdown signal sent") r.Stop() + err := proxyService.Stop() + if err != nil { + log.Error(err) + } os.Exit(0) }() } diff --git a/services/proxy.go b/services/proxy.go index 9e8b4826..11f01a28 100644 --- a/services/proxy.go +++ b/services/proxy.go @@ -6,6 +6,7 @@ import ( "net/http" "net/http/httputil" "net/url" + "time" "github.com/gin-contrib/cors" "github.com/gin-gonic/gin" @@ -60,7 +61,10 @@ func (s *ProxyService) Start() error { } func (s *ProxyService) Stop() error { - err := s.server.Shutdown(context.Background()) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) + defer cancel() + + err := s.server.Shutdown(ctx) if err != nil { return err }