diff --git a/.changelog/26171.txt b/.changelog/26171.txt new file mode 100644 index 000000000..2e154135e --- /dev/null +++ b/.changelog/26171.txt @@ -0,0 +1,3 @@ +```release-note:bug +agent: Fixed a bug to prevent panic during graceful server shutdown +``` diff --git a/command/agent/command.go b/command/agent/command.go index b6b541f54..b3c6ab528 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -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...")