Fix closed channel panic

This commit is contained in:
ppom 2023-09-22 23:18:08 +02:00
parent a119e0814b
commit be991e9665

View File

@ -37,6 +37,7 @@ func createDB(path string) *WriteDB {
func DatabaseManager(c *Conf) { func DatabaseManager(c *Conf) {
logDB, flushDB := c.RotateDB(true) logDB, flushDB := c.RotateDB(true)
close(startupMatchesC)
c.manageLogs(logDB, flushDB) c.manageLogs(logDB, flushDB)
} }
@ -63,7 +64,6 @@ func (c *Conf) manageLogs(logDB *WriteDB, flushDB *WriteDB) {
} }
func (c *Conf) RotateDB(startup bool) (*WriteDB, *WriteDB) { func (c *Conf) RotateDB(startup bool) (*WriteDB, *WriteDB) {
defer close(startupMatchesC)
var ( var (
doesntExist bool doesntExist bool
err error err error
@ -192,7 +192,6 @@ func rotateDB(c *Conf, logDec *gob.Decoder, flushDec *gob.Decoder, logEnc *gob.E
// store matches // store matches
if !entry.Exec && entry.T.Add(filter.retryDuration).Unix() > now.Unix() { if !entry.Exec && entry.T.Add(filter.retryDuration).Unix() > now.Unix() {
if startup { if startup {
log.Println("DEBUG db send match")
startupMatchesC <- PFT{entry.Pattern, filter, entry.T} startupMatchesC <- PFT{entry.Pattern, filter, entry.T}
} }
@ -202,7 +201,6 @@ func rotateDB(c *Conf, logDec *gob.Decoder, flushDec *gob.Decoder, logEnc *gob.E
// replay executions // replay executions
if entry.Exec && entry.T.Add(*filter.longuestActionDuration).Unix() > now.Unix() { if entry.Exec && entry.T.Add(*filter.longuestActionDuration).Unix() > now.Unix() {
if startup { if startup {
log.Println("DEBUG db send match")
cleanMatchesC <- PF{entry.Pattern, filter} cleanMatchesC <- PF{entry.Pattern, filter}
filter.sendActions(entry.Pattern, entry.T) filter.sendActions(entry.Pattern, entry.T)
} }