CLI: Data races in cli/internal/analytics/client.go
File: cli/internal/analytics/client.go
Problem: Two global variables are accessed from multiple goroutines without synchronization:
client (rudderstack.Client) — read/written in InitClient, TrackLoginSuccess, TrackSyncStarted, TrackSyncCompleted, TrackInitStarted, TrackInitCompleted, Close, and all other tracking functions.
cachedSyncEventDetails (*eventDetails) — read in getSyncEventDetails, written in refreshSyncEventDetails.
Both are accessed across goroutines (sync runs spawn goroutines that call tracking functions), but neither is protected by a mutex. The Go race detector reliably flags this.
Fix: Add sync.RWMutex for each variable. clientMu protects client, eventMu protects cachedSyncEventDetails. Introduce a getClient() helper that acquires a read lock.
Reproduction
Run cloudquery sync with the Go race detector enabled:
go run -race ./cli/main.go sync <config>
Or in tests:
go test -race ./cli/internal/analytics/...
The race detector will report concurrent read/write accesses to both client and cachedSyncEventDetails.
CLI: Data races in
cli/internal/analytics/client.goFile:
cli/internal/analytics/client.goProblem: Two global variables are accessed from multiple goroutines without synchronization:
client(rudderstack.Client) — read/written inInitClient,TrackLoginSuccess,TrackSyncStarted,TrackSyncCompleted,TrackInitStarted,TrackInitCompleted,Close, and all other tracking functions.cachedSyncEventDetails(*eventDetails) — read ingetSyncEventDetails, written inrefreshSyncEventDetails.Both are accessed across goroutines (sync runs spawn goroutines that call tracking functions), but neither is protected by a mutex. The Go race detector reliably flags this.
Fix: Add
sync.RWMutexfor each variable.clientMuprotectsclient,eventMuprotectscachedSyncEventDetails. Introduce agetClient()helper that acquires a read lock.Reproduction
Run
cloudquery syncwith the Go race detector enabled:Or in tests:
go test -race ./cli/internal/analytics/...The race detector will report concurrent read/write accesses to both
clientandcachedSyncEventDetails.