From 169379359c1c61761c041974999c1187ea386feb Mon Sep 17 00:00:00 2001 From: Martin Ivanov Date: Fri, 4 Nov 2022 16:17:21 +0200 Subject: [PATCH] Change the shutdown procedure to deregister fabio from the registry and then shutdown the proxy (#908) * change shutdown procedure to deregister and then shutdown the proxy * document proxy.deregistergraceperiod --- config/config.go | 1 + config/load.go | 1 + docs/content/ref/proxy.deregistergraceperiod.md | 15 +++++++++++++++ fabio.properties | 11 +++++++++++ main.go | 8 ++++---- 5 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 docs/content/ref/proxy.deregistergraceperiod.md diff --git a/config/config.go b/config/config.go index 08d37fe71..b84c7e18e 100644 --- a/config/config.go +++ b/config/config.go @@ -63,6 +63,7 @@ type Proxy struct { NoRouteStatus int MaxConn int ShutdownWait time.Duration + DeregisterGracePeriod time.Duration DialTimeout time.Duration ResponseHeaderTimeout time.Duration KeepAliveTimeout time.Duration diff --git a/config/load.go b/config/load.go index fd24d8513..2c37d5e02 100644 --- a/config/load.go +++ b/config/load.go @@ -138,6 +138,7 @@ func load(cmdline, environ, envprefix []string, props *properties.Properties) (c f.StringVar(&cfg.Proxy.Matcher, "proxy.matcher", defaultConfig.Proxy.Matcher, "path matching algorithm") f.IntVar(&cfg.Proxy.NoRouteStatus, "proxy.noroutestatus", defaultConfig.Proxy.NoRouteStatus, "status code for invalid route. Must be three digits") f.DurationVar(&cfg.Proxy.ShutdownWait, "proxy.shutdownwait", defaultConfig.Proxy.ShutdownWait, "time for graceful shutdown") + f.DurationVar(&cfg.Proxy.DeregisterGracePeriod, "proxy.deregistergraceperiod", defaultConfig.Proxy.DeregisterGracePeriod, "time to wait after deregistering from a registry") f.DurationVar(&cfg.Proxy.DialTimeout, "proxy.dialtimeout", defaultConfig.Proxy.DialTimeout, "connection timeout for backend connections") f.DurationVar(&cfg.Proxy.ResponseHeaderTimeout, "proxy.responseheadertimeout", defaultConfig.Proxy.ResponseHeaderTimeout, "response header timeout") f.DurationVar(&cfg.Proxy.KeepAliveTimeout, "proxy.keepalivetimeout", defaultConfig.Proxy.KeepAliveTimeout, "keep-alive timeout") diff --git a/docs/content/ref/proxy.deregistergraceperiod.md b/docs/content/ref/proxy.deregistergraceperiod.md new file mode 100644 index 000000000..ce4a87341 --- /dev/null +++ b/docs/content/ref/proxy.deregistergraceperiod.md @@ -0,0 +1,15 @@ +--- +title: "proxy.deregistergraceperiod" +--- + +`proxy.deregistergraceperiod` configures the time to wait before +shutting down the proxies de-registering from the service registry. + +After a signal is caught Fabio will immediately de-register from the +service registry and wait for `proxy.deregistergraceperiod` letting +in-flight requests finish after which it will continue with shutting +down the proxy. + +The default is + + proxy.deregistergraceperiod = 0s diff --git a/fabio.properties b/fabio.properties index 852281729..8e717f1c7 100644 --- a/fabio.properties +++ b/fabio.properties @@ -356,6 +356,17 @@ # # proxy.shutdownwait = 0s +#proxy.deregistergraceperiod configures the time to wait before +#shutting down the proxies de-registering from the service registry. +# +#After a signal is caught Fabio will immediately de-register from the +#service registry and wait for `proxy.deregistergraceperiod` letting +#in-flight requests finish after which it will continue with shutting +#down the proxy. +# +#The default is +# +#proxy.deregistergraceperiod = 0s # proxy.responseheadertimeout configures the response header timeout. # diff --git a/main.go b/main.go index 0652b921d..8d3caba59 100644 --- a/main.go +++ b/main.go @@ -114,14 +114,14 @@ func main() { exit.Listen(func(s os.Signal) { atomic.StoreInt32(&shuttingDown, 1) + if registry.Default != nil { + registry.Default.DeregisterAll() + } + time.Sleep(cfg.Proxy.DeregisterGracePeriod) proxy.Shutdown(cfg.Proxy.ShutdownWait) if prof != nil { prof.Stop() } - if registry.Default == nil { - return - } - registry.Default.DeregisterAll() }) metrics, err := metrics.Initialize(&cfg.Metrics)