From 3ba001f8d718cda63069c6c4e96d072e247b042b Mon Sep 17 00:00:00 2001 From: Cnly Date: Sat, 24 Jul 2021 18:01:58 +0800 Subject: [PATCH] http: fix serve http exits directly after starting --- cmd/serve/http/http.go | 1 + lib/http/http.go | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/cmd/serve/http/http.go b/cmd/serve/http/http.go index dab1489d7..592580826 100644 --- a/cmd/serve/http/http.go +++ b/cmd/serve/http/http.go @@ -69,6 +69,7 @@ control the stats printing. return err } s.Bind(router) + httplib.Wait() return nil }) }, diff --git a/lib/http/http.go b/lib/http/http.go index 61525bab4..28c2596d7 100644 --- a/lib/http/http.go +++ b/lib/http/http.go @@ -231,6 +231,11 @@ func (s *server) Serve() { } } +// Wait blocks while the server is serving requests +func (s *server) Wait() { + s.closing.Wait() +} + // Router returns the server base router func (s *server) Router() chi.Router { return s.baseRouter @@ -291,6 +296,11 @@ func Restart() error { return start() } +// Wait blocks while the default http server is serving requests +func Wait() { + defaultServer.Wait() +} + // Start the default server func start() error { defaultServerMutex.Lock()