Skip to content

Commit

Permalink
Wait for both api and agent chans if necessary when daemonize is fals…
Browse files Browse the repository at this point in the history
…e or running on windows (#2155)
  • Loading branch information
blotus authored Apr 4, 2023
1 parent 0279e54 commit 1e018bd
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions cmd/crowdsec/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,24 @@ func Serve(cConfig *csconfig.Config, apiReady chan bool, agentReady chan bool) e
return HandleSignals(cConfig)
}

for {
select {
case <-apiTomb.Dead():
waitChans := make([]<-chan struct{}, 0)

if !cConfig.DisableAgent {
waitChans = append(waitChans, crowdsecTomb.Dead())
}

if !cConfig.DisableAPI {
waitChans = append(waitChans, apiTomb.Dead())
}

for _, ch := range waitChans {
<-ch
switch ch {
case apiTomb.Dead():
log.Infof("api shutdown")
return nil
case <-crowdsecTomb.Dead():
case crowdsecTomb.Dead():
log.Infof("crowdsec shutdown")
return nil
}
}
return nil
}

0 comments on commit 1e018bd

Please sign in to comment.