Skip to content

Commit

Permalink
fix: data race on count pending Falco events (#112)
Browse files Browse the repository at this point in the history
* test: add sleep on TestNewWithFalcoSidekickURL

Signed-off-by: Dwi Siswanto <me@dw1.io>

* fix: data race on count pending Falco events

Signed-off-by: Dwi Siswanto <me@dw1.io>

---------

Signed-off-by: Dwi Siswanto <me@dw1.io>
  • Loading branch information
dwisiswant0 committed Oct 19, 2023
1 parent f8dbfbd commit a39d234
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions falcosidekick.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,18 @@ func (t *Teler) checkFalcoEvents() {

// Check for pending Falco events every 5 seconds.
for range ticker.C {
// Lock the FalcoSidekick event
t.falcoSidekick.sl.Lock()

// Get the count of pending Falco events.
c := len(t.falcoSidekick.events)
if c > 0 {
// Send pending Falco events to FalcoSidekick.
t.sendFalcoEvents()
}

// Unlock the FalcoSidekick event
t.falcoSidekick.sl.Unlock()
}
}

Expand Down
3 changes: 3 additions & 0 deletions teler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"strings"
"testing"
"time"

"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -286,6 +287,8 @@ func TestNewWithFalcoSidekickURL(t *testing.T) {
if err != nil {
t.Fatal(err)
}

time.Sleep(5 * time.Second)
}

func TestNewWithVerbose(t *testing.T) {
Expand Down

0 comments on commit a39d234

Please sign in to comment.