Skip to content

Commit

Permalink
Merge pull request #26 from kubescape/panic
Browse files Browse the repository at this point in the history
do not write on closed cooldown queue
  • Loading branch information
matthyx authored Dec 21, 2023
2 parents 7584c90 + adc7c13 commit 4ed3fd8
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions utils/cooldownqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
// will silently drop the event. When the cooldown resets and a client puts the
// same event into the queue, it will be forwarded to the output channel
type CooldownQueue struct {
closed bool
seenEvents *lru.LRU[string, bool]
// inner channel for producing events
innerChan chan watch.Event
Expand Down Expand Up @@ -53,6 +54,9 @@ func makeEventKey(e watch.Event) string {

// Enqueue enqueues an event in the Cooldown Queue
func (q *CooldownQueue) Enqueue(e watch.Event) {
if q.closed {
return
}
eventKey := makeEventKey(e)
_, exists := q.seenEvents.Get(eventKey)
if exists {
Expand All @@ -65,5 +69,6 @@ func (q *CooldownQueue) Enqueue(e watch.Event) {
}

func (q *CooldownQueue) Stop() {
q.closed = true
close(q.innerChan)
}

0 comments on commit 4ed3fd8

Please sign in to comment.