Skip to content

Commit

Permalink
fix #258: fix race condition for stopping killed daemons
Browse files Browse the repository at this point in the history
  • Loading branch information
F1bonacc1 committed Nov 9, 2024
1 parent 994e543 commit ff2eaa9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/app/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ loop:
}

func (p *Process) notifyDaemonStopped() {
if p.isDaemonLaunched() {
if p.procConf.IsDaemon {
p.procStateChan <- types.ProcessStateCompleted
}
}
Expand Down
35 changes: 18 additions & 17 deletions src/app/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,24 +337,25 @@ func (p *Process) waitForCompletion() int {
}

func (p *Process) waitUntilReady() bool {
for {
select {
case <-p.procReadyCtx.Done():
if p.procState.Health == types.ProcessHealthReady {
return true
}
log.Error().Msgf("Process %s was aborted and won't become ready", p.getName())
p.setExitCode(1)
return false
case <-p.procLogReadyCtx.Done():
err := context.Cause(p.procLogReadyCtx)
if errors.Is(err, context.Canceled) {
return true
}
log.Error().Err(err).Msgf("Process %s was aborted and won't become log ready", p.getName())
return false
}
<-p.procReadyCtx.Done()
if p.procState.Health == types.ProcessHealthReady {
return true
}
log.Error().Msgf("Process %s was aborted and won't become ready", p.getName())
p.setExitCode(1)
return false

}

func (p *Process) waitUntilLogReady() bool {
<-p.procLogReadyCtx.Done()
err := context.Cause(p.procLogReadyCtx)
if errors.Is(err, context.Canceled) {
return true
}
log.Error().Err(err).Msgf("Process %s was aborted and won't become log ready", p.getName())
return false

}

func (p *Process) wontRun() {
Expand Down
2 changes: 1 addition & 1 deletion src/app/project_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (p *ProjectRunner) waitIfNeeded(process *types.ProcessConfig) error {
}
case types.ProcessConditionLogReady:
log.Info().Msgf("%s is waiting for %s log line %s", process.ReplicaName, k, runningProc.procConf.ReadyLogLine)
ready := runningProc.waitUntilReady()
ready := runningProc.waitUntilLogReady()
if !ready {
return fmt.Errorf("process %s depended on %s to become ready, but it was terminated", process.ReplicaName, k)
}
Expand Down

0 comments on commit ff2eaa9

Please sign in to comment.