From 314d99d2b462eba58c9700b4ba34edd71114bdb5 Mon Sep 17 00:00:00 2001 From: wanyaoqi Date: Thu, 28 Feb 2019 21:15:45 +0800 Subject: [PATCH] fix metadata port, appsrv add check quitHandlerRegisted --- pkg/appsrv/appsrv.go | 12 +++++++++--- pkg/hostman/hostinfo/hostbridge/hostbridge.go | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/appsrv/appsrv.go b/pkg/appsrv/appsrv.go index 6d99af64cf..ef8cfbf227 100644 --- a/pkg/appsrv/appsrv.go +++ b/pkg/appsrv/appsrv.go @@ -53,6 +53,8 @@ const ( DEFAULT_PROCESS_TIMEOUT = 15 * time.Second ) +var quitHandlerRegisted bool + func NewApplication(name string, connMax int, db bool) *Application { app := Application{name: name, context: context.Background(), @@ -333,6 +335,12 @@ func (app *Application) initServer(addr string) *http.Server { } func (app *Application) registerCleanShutdown(s *http.Server, onStop func()) { + if quitHandlerRegisted { + log.Warningf("Application quit handler registed, duplicated!!!") + return + } else { + quitHandlerRegisted = true + } app.idleConnsClosed = make(chan struct{}) // dump goroutine stack @@ -388,9 +396,7 @@ func (app *Application) ListenAndServeWithCleanup(addr string, onStop func()) { func (app *Application) ListenAndServeTLSWithCleanup(addr string, certFile, keyFile string, onStop func()) { s := app.initServer(addr) - if onStop != nil { - app.registerCleanShutdown(s, onStop) - } + app.registerCleanShutdown(s, onStop) var err error if len(certFile) == 0 && len(keyFile) == 0 { diff --git a/pkg/hostman/hostinfo/hostbridge/hostbridge.go b/pkg/hostman/hostinfo/hostbridge/hostbridge.go index 7cbc697566..00915d5efb 100644 --- a/pkg/hostman/hostinfo/hostbridge/hostbridge.go +++ b/pkg/hostman/hostinfo/hostbridge/hostbridge.go @@ -447,7 +447,7 @@ func (o *SOVSBridgeDriver) GetOfRules(nic jsonutils.JSONObject) []SRule { } func (o *SOVSBridgeDriver) GetMetadataServerPort() int { - return options.HostOptions.Port + return options.HostOptions.Port + 1000 } func (o *SOVSBridgeDriver) RegisterHostlocalServer(mac, ip string) error {