From 738aaa7ab8e4b853b5c1978b09a590f6092e64e7 Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Thu, 26 Aug 2021 16:49:28 +0800 Subject: [PATCH] fix(keystone): appsrv listen multi port failed cause of race condition --- pkg/appsrv/appsrv.go | 10 ++++++---- pkg/cloudcommon/app/app.go | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/appsrv/appsrv.go b/pkg/appsrv/appsrv.go index a9bd0afdf1..ff92549b0e 100644 --- a/pkg/appsrv/appsrv.go +++ b/pkg/appsrv/appsrv.go @@ -65,6 +65,7 @@ type Application struct { isExiting bool idleConnsClosed chan struct{} httpServer *http.Server + slaveHttpServer *http.Server } const ( @@ -490,15 +491,16 @@ func (app *Application) ListenAndServeWithoutCleanup(addr, certFile, keyFile str } func (app *Application) ListenAndServeTLSWithCleanup2(addr string, certFile, keyFile string, onStop func(), isMaster bool) { + httpSrv := app.initServer(addr) if isMaster { app.addDefaultHandlers() AddPProfHandler(app) - } - app.httpServer = app.initServer(addr) - if isMaster { + app.httpServer = httpSrv app.registerCleanShutdown(app.httpServer, onStop) + } else { + app.slaveHttpServer = httpSrv } - app.listenAndServeInternal(app.httpServer, certFile, keyFile) + app.listenAndServeInternal(httpSrv, certFile, keyFile) if isMaster { app.waitCleanShutdown() } diff --git a/pkg/cloudcommon/app/app.go b/pkg/cloudcommon/app/app.go index 44cc574b2f..3b92d6e70e 100644 --- a/pkg/cloudcommon/app/app.go +++ b/pkg/cloudcommon/app/app.go @@ -53,7 +53,7 @@ func ServeForeverExtended(app *appsrv.Application, options *common_options.BaseO if options.EnableSsl { proto = "https" } - log.Infof("Start listen on %s://%s", proto, addr) + log.Infof("Start listen on %s://%s, isMaster: %v", proto, addr, isMaster) var certfile string var sslfile string if options.EnableSsl {