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:
Chris Roberts
2025-07-01 15:54:03 -07:00
committed by GitHub
parent 362690ddd1
commit 493e7b2faa
2 changed files with 10 additions and 6 deletions

3
.changelog/26171.txt Normal file
View File

@@ -0,0 +1,3 @@
```release-note:bug
agent: Fixed a bug to prevent panic during graceful server shutdown
```

View File

@@ -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...")