From b812e74d6f1f51d37a518e3cc2c0f8b60b7b3bcf Mon Sep 17 00:00:00 2001 From: fangjianwei Date: Sat, 24 Jul 2021 12:57:56 +0800 Subject: [PATCH] Fixed http listener error. (#843) --- rest/internal/starter.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rest/internal/starter.go b/rest/internal/starter.go index ddd08f2a..e378b6d6 100644 --- a/rest/internal/starter.go +++ b/rest/internal/starter.go @@ -23,7 +23,7 @@ func StartHttps(host string, port int, certFile, keyFile string, handler http.Ha }) } -func start(host string, port int, handler http.Handler, run func(srv *http.Server) error) error { +func start(host string, port int, handler http.Handler, run func(srv *http.Server) error) (err error) { server := &http.Server{ Addr: fmt.Sprintf("%s:%d", host, port), Handler: handler, @@ -31,7 +31,11 @@ func start(host string, port int, handler http.Handler, run func(srv *http.Serve waitForCalled := proc.AddWrapUpListener(func() { server.Shutdown(context.Background()) }) - defer waitForCalled() + defer func() { + if err == http.ErrServerClosed { + waitForCalled() + } + }() return run(server) }