From ba77ec0ecf7b22f76f4c0377ce16b79e5b78125d Mon Sep 17 00:00:00 2001 From: Ingo Oppermann Date: Thu, 10 Apr 2025 15:30:40 +0200 Subject: [PATCH] Fix crash while stopping a process that is currently starting --- process/process.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/process/process.go b/process/process.go index 36fd50b5..e05c6345 100644 --- a/process/process.go +++ b/process/process.go @@ -796,8 +796,18 @@ func (p *process) stop(wait bool, reason string) error { return nil } + // If the process in starting state, wait until the process has been started + for { + if p.getState() == stateStarting { + time.Sleep(500 * time.Millisecond) + continue + } + + break + } + // If the process is already in the finishing state, don't do anything - if p.getState() == stateFinishing { + if state, _ := p.setState(stateFinishing); state == stateFinishing { return nil } @@ -805,8 +815,6 @@ func (p *process) stop(wait bool, reason string) error { p.stopReason = reason p.stopReasonLock.Unlock() - p.setState(stateFinishing) - p.logger.Info().Log("Stopping") p.debuglogger.WithFields(log.Fields{ "state": p.getStateString(),