From e048c7b2be1371aad6227ee14032ec174534c284 Mon Sep 17 00:00:00 2001 From: Salah Al Saleh Date: Tue, 31 Oct 2023 13:21:40 -0700 Subject: [PATCH] Handle race condition where events are reported out of order (#4115) --- pkg/reporting/app_airgap.go | 10 ++++++++++ pkg/reporting/app_online.go | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/pkg/reporting/app_airgap.go b/pkg/reporting/app_airgap.go index e8cb5c0a14..ca94895d9c 100644 --- a/pkg/reporting/app_airgap.go +++ b/pkg/reporting/app_airgap.go @@ -2,6 +2,7 @@ package reporting import ( "strconv" + "sync" "time" "github.com/pkg/errors" @@ -10,7 +11,16 @@ import ( "github.com/replicatedhq/kots/pkg/util" ) +var airgapAppInfoMtx sync.Mutex + func (r *AirgapReporter) SubmitAppInfo(appID string) error { + // make sure events are reported in order + airgapAppInfoMtx.Lock() + defer func() { + time.Sleep(1 * time.Second) + airgapAppInfoMtx.Unlock() + }() + a, err := r.store.GetApp(appID) if err != nil { if r.store.IsNotFound(err) { diff --git a/pkg/reporting/app_online.go b/pkg/reporting/app_online.go index 2bd7aec174..32b40bfb66 100644 --- a/pkg/reporting/app_online.go +++ b/pkg/reporting/app_online.go @@ -4,13 +4,24 @@ import ( "encoding/base64" "fmt" "net/http" + "sync" + "time" "github.com/pkg/errors" "github.com/replicatedhq/kots/pkg/store" "github.com/replicatedhq/kots/pkg/util" ) +var onlineAppInfoMtx sync.Mutex + func (r *OnlineReporter) SubmitAppInfo(appID string) error { + // make sure events are reported in order + onlineAppInfoMtx.Lock() + defer func() { + time.Sleep(1 * time.Second) + onlineAppInfoMtx.Unlock() + }() + a, err := store.GetStore().GetApp(appID) if err != nil { if store.GetStore().IsNotFound(err) {