Skip to content

Commit

Permalink
Handle race condition where events are reported out of order (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgalsaleh authored Oct 31, 2023
1 parent 9eb386b commit f77cc32
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/heartbeat/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"sync"
"time"

"github.com/pkg/errors"
Expand All @@ -19,6 +20,8 @@ import (
"k8s.io/client-go/kubernetes"
)

var heartbeatMtx sync.Mutex

func SendAppHeartbeat(clientset kubernetes.Interface, sdkStore store.Store) error {
license := sdkStore.GetLicense()

Expand All @@ -30,6 +33,13 @@ func SendAppHeartbeat(clientset kubernetes.Interface, sdkStore store.Store) erro
return nil
}

// make sure events are reported in order
heartbeatMtx.Lock()
defer func() {
time.Sleep(1 * time.Second)
heartbeatMtx.Unlock()
}()

heartbeatInfo := GetHeartbeatInfo(sdkStore)

if util.IsAirgap() {
Expand Down

0 comments on commit f77cc32

Please sign in to comment.