mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
command: prevent early exit from graceful shutdown (#26023)
While waiting for the agent to leave during a graceful shutdown the wait can be interrupted immediately if another signal is received. It is common that while waiting a `SIGPIPE` is received from journald causing the wait to end early. This results in the agent not finishing the leave process and reporting an error when the process has stopped. Instead of allowing any signal to interrupt the wait, the signal is checked for a `SIGPIPE` and if matched will continue waiting.
This commit is contained in:
3
.changelog/26023.txt
Normal file
3
.changelog/26023.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
```release-note:bug
|
||||||
|
agent: Fixed bug where agent would exit early from graceful shutdown when managed by systemd
|
||||||
|
```
|
||||||
@@ -1007,13 +1007,25 @@ func (c *Command) terminateGracefully(signalCh chan os.Signal, sdSock io.Writer)
|
|||||||
|
|
||||||
delay := time.NewTimer(timeout)
|
delay := time.NewTimer(timeout)
|
||||||
|
|
||||||
// Wait for leave or another signal
|
// Wait for leave or another signal to be received
|
||||||
select {
|
for {
|
||||||
case <-signalCh:
|
select {
|
||||||
return 1
|
case sig := <-signalCh:
|
||||||
case <-delay.C:
|
// If a SIGPIPE is received, ignore it and
|
||||||
return 1
|
// continue waiting
|
||||||
case <-gracefulCh:
|
if sig == syscall.SIGPIPE {
|
||||||
|
c.agent.logger.Trace("caught SIGPIPE during graceful shutdown, ignoring")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
c.agent.logger.Trace("caught signal during graceful shutdown", "signal", sig)
|
||||||
|
|
||||||
|
return 1
|
||||||
|
case <-delay.C:
|
||||||
|
return 1
|
||||||
|
case <-gracefulCh:
|
||||||
|
}
|
||||||
|
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
Reference in New Issue
Block a user