Skip to content

Commit

Permalink
fix: race condition in LogRequest (tom-draper#53)
Browse files Browse the repository at this point in the history
note: this is a theoretical fix and has not been properly tested
  • Loading branch information
JasonLovesDoggo authored Dec 21, 2024
1 parent a38ff59 commit 655c05c
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 655c05c

Please sign in to comment.