@@ -62,10 +62,6 @@ type Process struct {
6262 // used to block on multiple start() calls
6363 waitStarting sync.WaitGroup
6464
65- // for managing shutdown state
66- shutdownCtx context.Context
67- shutdownCancel context.CancelFunc
68-
6965 // for managing concurrency limits
7066 concurrencyLimitSemaphore chan struct {}
7167
@@ -77,7 +73,6 @@ type Process struct {
7773}
7874
7975func NewProcess (ID string , healthCheckTimeout int , config ModelConfig , processLogger * LogMonitor , proxyLogger * LogMonitor ) * Process {
80- ctx , cancel := context .WithCancel (context .Background ())
8176 concurrentLimit := 10
8277 if config .ConcurrencyLimit > 0 {
8378 concurrentLimit = config .ConcurrencyLimit
@@ -93,8 +88,6 @@ func NewProcess(ID string, healthCheckTimeout int, config ModelConfig, processLo
9388 healthCheckTimeout : healthCheckTimeout ,
9489 healthCheckLoopInterval : 5 * time .Second , /* default, can not be set by user - used for testing */
9590 state : StateStopped ,
96- shutdownCtx : ctx ,
97- shutdownCancel : cancel ,
9891
9992 // concurrency limit
10093 concurrencyLimitSemaphore : make (chan struct {}, concurrentLimit ),
@@ -266,15 +259,18 @@ func (p *Process) start() error {
266259 loop:
267260 // Ready Check loop
268261 for {
262+ currentState := p .CurrentState ()
263+ if currentState != StateStarting {
264+ return errors .New ("health check interrupted due to shutdown" )
265+ }
266+
269267 select {
270268 case <- checkDeadline .Done ():
271269 if curState , err := p .swapState (StateStarting , StateFailed ); err != nil {
272270 return fmt .Errorf ("health check timed out after %vs AND state swap failed: %v, current state: %v" , maxDuration .Seconds (), err , curState )
273271 } else {
274272 return fmt .Errorf ("health check timed out after %vs" , maxDuration .Seconds ())
275273 }
276- case <- p .shutdownCtx .Done ():
277- return errors .New ("health check interrupted due to shutdown" )
278274 case exitErr := <- p .cmdWaitChan :
279275 if exitErr != nil {
280276 p .proxyLogger .Warnf ("<%s> upstream command exited prematurely with error: %v" , p .ID , exitErr )
@@ -392,7 +388,6 @@ func (p *Process) Shutdown() {
392388 return
393389 }
394390
395- p .shutdownCancel ()
396391 p .stopCommand (p .gracefulStopTimeout )
397392
398393 // just force it to this state since there is no recovery from shutdown
0 commit comments