From a39d234da00c92964be57f5fe795041a15725372 Mon Sep 17 00:00:00 2001 From: Dwi Siswanto Date: Thu, 19 Oct 2023 14:25:00 +0700 Subject: [PATCH] fix: data race on count pending Falco events (#112) * test: add sleep on TestNewWithFalcoSidekickURL Signed-off-by: Dwi Siswanto * fix: data race on count pending Falco events Signed-off-by: Dwi Siswanto --------- Signed-off-by: Dwi Siswanto --- falcosidekick.go | 6 ++++++ teler_test.go | 3 +++ 2 files changed, 9 insertions(+) diff --git a/falcosidekick.go b/falcosidekick.go index fdd0eeb7..c06a7456 100644 --- a/falcosidekick.go +++ b/falcosidekick.go @@ -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() } } diff --git a/teler_test.go b/teler_test.go index d1befd82..98219a62 100644 --- a/teler_test.go +++ b/teler_test.go @@ -11,6 +11,7 @@ import ( "os" "strings" "testing" + "time" "net/http" "net/http/httptest" @@ -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) {