Make checking for process killed status more robust
This commit is contained in:
@@ -70,6 +70,9 @@ type Process struct {
|
|||||||
|
|
||||||
// stop timeout waiting for graceful shutdown
|
// stop timeout waiting for graceful shutdown
|
||||||
gracefulStopTimeout time.Duration
|
gracefulStopTimeout time.Duration
|
||||||
|
|
||||||
|
// track that this happened
|
||||||
|
upstreamWasStoppedWithKill bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewProcess(ID string, healthCheckTimeout int, config ModelConfig, processLogger *LogMonitor, proxyLogger *LogMonitor) *Process {
|
func NewProcess(ID string, healthCheckTimeout int, config ModelConfig, processLogger *LogMonitor, proxyLogger *LogMonitor) *Process {
|
||||||
@@ -97,7 +100,8 @@ func NewProcess(ID string, healthCheckTimeout int, config ModelConfig, processLo
|
|||||||
concurrencyLimitSemaphore: make(chan struct{}, concurrentLimit),
|
concurrencyLimitSemaphore: make(chan struct{}, concurrentLimit),
|
||||||
|
|
||||||
// stop timeout
|
// stop timeout
|
||||||
gracefulStopTimeout: 5 * time.Second,
|
gracefulStopTimeout: 5 * time.Second,
|
||||||
|
upstreamWasStoppedWithKill: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,9 +221,12 @@ func (p *Process) start() error {
|
|||||||
|
|
||||||
// there is a race condition when SIGKILL is used, p.cmd.Wait() returns, and then
|
// there is a race condition when SIGKILL is used, p.cmd.Wait() returns, and then
|
||||||
// the code below fires, putting an error into cmdWaitChan. This code is to prevent this
|
// the code below fires, putting an error into cmdWaitChan. This code is to prevent this
|
||||||
if exitErr != nil && exitErr.Error() == "signal: killed" {
|
if p.upstreamWasStoppedWithKill {
|
||||||
|
p.proxyLogger.Debugf("<%s> process was killed, NOT sending exitErr: %v", p.ID, exitErr)
|
||||||
|
p.upstreamWasStoppedWithKill = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
p.cmdWaitChan <- exitErr
|
p.cmdWaitChan <- exitErr
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -400,6 +407,7 @@ func (p *Process) stopCommand(sigtermTTL time.Duration) {
|
|||||||
select {
|
select {
|
||||||
case <-sigtermTimeout.Done():
|
case <-sigtermTimeout.Done():
|
||||||
p.proxyLogger.Debugf("<%s> Process timed out waiting to stop, sending KILL signal (normal during shutdown)", p.ID)
|
p.proxyLogger.Debugf("<%s> Process timed out waiting to stop, sending KILL signal (normal during shutdown)", p.ID)
|
||||||
|
p.upstreamWasStoppedWithKill = true
|
||||||
if err := p.cmd.Process.Kill(); err != nil {
|
if err := p.cmd.Process.Kill(); err != nil {
|
||||||
p.proxyLogger.Errorf("<%s> Failed to kill process: %v", p.ID, err)
|
p.proxyLogger.Errorf("<%s> Failed to kill process: %v", p.ID, err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user