Skip to content

Commit f727c23

Browse files
committed
fix(rule-engine): Guard rule matches slice with mutex
1 parent b0dabe0 commit f727c23

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pkg/rules/engine.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ type Engine struct {
5959
psnap ps.Snapshotter
6060

6161
matches []*ruleMatch
62+
mmu sync.Mutex // guards the rule matches slice
6263
sequences []*sequenceState
6364

6465
scavenger *time.Ticker
@@ -306,6 +307,8 @@ func (e *Engine) ProcessEvent(evt *kevent.Kevent) (bool, error) {
306307
// defined in the rule definition.
307308
func (e *Engine) processActions() error {
308309
defer e.clearMatches()
310+
e.mmu.Lock()
311+
defer e.mmu.Unlock()
309312
for _, m := range e.matches {
310313
f, evts := m.ctx.Filter, m.ctx.Events
311314
filterMatches.Add(f.Name, 1)
@@ -344,12 +347,16 @@ func (e *Engine) appendMatch(f *config.FilterConfig, evts ...*kevent.Kevent) {
344347
Events: evts,
345348
Filter: f,
346349
}
350+
e.mmu.Lock()
351+
defer e.mmu.Unlock()
347352
e.matches = append(e.matches, &ruleMatch{ctx: ctx})
348353
if e.matchFunc != nil {
349354
e.matchFunc(f, evts...)
350355
}
351356
}
352357

353358
func (e *Engine) clearMatches() {
359+
e.mmu.Lock()
360+
defer e.mmu.Unlock()
354361
e.matches = make([]*ruleMatch, 0)
355362
}

0 commit comments

Comments
 (0)