Skip to content

Commit

Permalink
Change the shutdown procedure to deregister fabio from the registry a…
Browse files Browse the repository at this point in the history
…nd then shutdown the proxy (#908)

* change shutdown procedure to deregister and then shutdown the proxy

* document proxy.deregistergraceperiod
  • Loading branch information
martinivanov authored Nov 4, 2022
1 parent 0d17388 commit 1693793
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
15 changes: 15 additions & 0 deletions docs/content/ref/proxy.deregistergraceperiod.md
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions fabio.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1693793

Please sign in to comment.