Timeout on shutdown while waiting for events to be flushed (#2423)
This commit is contained in:
parent
afeb541eac
commit
caaed7c515
|
@ -141,12 +141,24 @@ func ShutdownCrowdsecRoutines() error {
|
||||||
time.Sleep(1 * time.Second) // ugly workaround for now
|
time.Sleep(1 * time.Second) // ugly workaround for now
|
||||||
outputsTomb.Kill(nil)
|
outputsTomb.Kill(nil)
|
||||||
|
|
||||||
if err := outputsTomb.Wait(); err != nil {
|
done := make(chan error, 1)
|
||||||
log.Warningf("Ouputs returned error : %s", err)
|
go func() {
|
||||||
reterr = err
|
done <- outputsTomb.Wait()
|
||||||
|
}()
|
||||||
|
|
||||||
|
// wait for outputs to finish, max 3 seconds
|
||||||
|
select {
|
||||||
|
case err := <-done:
|
||||||
|
if err != nil {
|
||||||
|
log.Warningf("Outputs returned error : %s", err)
|
||||||
|
reterr = err
|
||||||
|
}
|
||||||
|
log.Debugf("outputs are done")
|
||||||
|
case <-time.After(3 * time.Second):
|
||||||
|
// this can happen if outputs are stuck in a http retry loop
|
||||||
|
log.Warningf("Outputs didn't finish in time, some events may have not been flushed")
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("outputs are done")
|
|
||||||
// He's dead, Jim.
|
// He's dead, Jim.
|
||||||
crowdsecTomb.Kill(nil)
|
crowdsecTomb.Kill(nil)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue