From 35cb9100cd1081a2f5e316ac379c60d2d8040e54 Mon Sep 17 00:00:00 2001 From: emile Date: Tue, 24 Nov 2015 09:12:20 +0100 Subject: [PATCH] Add mutex around prepareserver --- traefik.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/traefik.go b/traefik.go index 72594b690..ee9668a40 100644 --- a/traefik.go +++ b/traefik.go @@ -26,6 +26,7 @@ import ( "github.com/mailgun/oxy/roundrobin" "github.com/thoas/stats" "gopkg.in/alecthomas/kingpin.v2" + "sync" ) var ( @@ -53,6 +54,7 @@ func main() { defer close(stopChan) var providers = []provider.Provider{} signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) + var serverLock sync.Mutex // load global configuration globalConfiguration := LoadFileConfig(*globalConfigFile) @@ -124,6 +126,7 @@ func main() { newConfigurationRouter, err := LoadConfig(newConfigurations, globalConfiguration) if err == nil { + serverLock.Lock() currentConfigurations = newConfigurations configurationRouter = newConfigurationRouter oldServer := srv @@ -138,6 +141,7 @@ func main() { log.Info("Stopping old server") oldServer.Close() } + serverLock.Unlock() } else { log.Error("Error loading new configuration, aborted ", err) } @@ -199,11 +203,13 @@ func main() { //negroni.Use(middlewares.NewRoutes(configurationRouter)) var er error + serverLock.Lock() srv, er = prepareServer(configurationRouter, globalConfiguration, nil, loggerMiddleware, metrics) if er != nil { log.Fatal("Error preparing server: ", er) } go startServer(srv, globalConfiguration) + serverLock.Unlock() <-stopChan log.Info("Shutting down")