You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cli/internal/analytics/client.go: data races on global client and cachedSyncEventDetails — no mutex protection #23168
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.
Activity