Skip to content

Commit

Permalink
Merge pull request #54 from JasonLovesDoggo/main
Browse files Browse the repository at this point in the history
fix: race condition in LogRequest (#58)
  • Loading branch information
tom-draper authored Dec 21, 2024
2 parents a38ff59 + 655c05c commit 4500ca8
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions analytics/go/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ func postRequest(apiKey string, requests []RequestData, framework string, privac
}

func LogRequest(apiKey string, request RequestData, framework string, privacyLevel int, serverURL string) {
if apiKey == "" {
return
}
now := time.Now()
requests = append(requests, request)
if time.Since(lastPosted) > time.Minute {
go postRequest(apiKey, requests, framework, privacyLevel, serverURL)
requests = nil
lastPosted = now
}
if apiKey == "" {
return
}
requests = append(requests, request)
if time.Since(lastPosted) > time.Minute {
requestsCopy := make([]RequestData, len(requests))
copy(requestsCopy, requests)

go postRequest(apiKey, requestsCopy, framework, privacyLevel, serverURL)
requests = nil
lastPosted = time.Now()
}
}

0 comments on commit 4500ca8

Please sign in to comment.