mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
command: prevent server panic on graceful shutdown (#26171)
When performing a graceful shutdown the client drain configuration is checked for a deadline which is appended to the timeout. When running as a server the client will not be set. Attempting to get the drain deadline will result in a panic. This checks for the client being available prior to fetching the deadline value.
This commit is contained in:
3
.changelog/26171.txt
Normal file
3
.changelog/26171.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
```release-note:bug
|
||||
agent: Fixed a bug to prevent panic during graceful server shutdown
|
||||
```
|
||||
@@ -989,13 +989,14 @@ func (c *Command) terminateGracefully(signalCh chan os.Signal, sdSock io.Writer)
|
||||
|
||||
timeout := gracefulTimeout
|
||||
|
||||
config := c.agent.client.GetConfig()
|
||||
if config == nil {
|
||||
c.Ui.Output("Unable to read the agent configuration, using the default graceful timeout")
|
||||
}
|
||||
if c.agent.client != nil {
|
||||
config := c.agent.client.GetConfig()
|
||||
|
||||
if config.Drain != nil && config.Drain.Deadline != 0 {
|
||||
timeout += config.Drain.Deadline
|
||||
if config == nil {
|
||||
c.Ui.Output("Unable to read the agent configuration, using the default graceful timeout")
|
||||
} else if config.Drain != nil && config.Drain.Deadline != 0 {
|
||||
timeout += config.Drain.Deadline
|
||||
}
|
||||
}
|
||||
|
||||
c.Ui.Output("Gracefully shutting down agent...")
|
||||
|
||||
Reference in New Issue
Block a user