Skip to content

Commit

Permalink
Handle race condition where events are reported out of order (#4115)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgalsaleh authored Oct 31, 2023
1 parent f237c37 commit e048c7b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/reporting/app_airgap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package reporting

import (
"strconv"
"sync"
"time"

"github.com/pkg/errors"
Expand All @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions pkg/reporting/app_online.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit e048c7b

Please sign in to comment.