Wait for both api and agent chans if necessary when daemonize is false or running on windows (#2155)

This commit is contained in:
blotus 2023-04-04 15:16:48 +02:00 committed by GitHub
parent 0279e549bd
commit 1e018bdaf8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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
}