#23168·cloudquery

cli/internal/analytics/client.go: data races on global client and cachedSyncEventDetails — no mutex protection

Author: praneshnikharCreated Jul 27, 2026Updated Jul 27, 2026

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:

  1. client (rudderstack.Client) — read/written in InitClient, TrackLoginSuccess, TrackSyncStarted, TrackSyncCompleted, TrackInitStarted, TrackInitCompleted, Close, and all other tracking functions.
  2. 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:

bash
go run -race ./cli/main.go sync <config>

Or in tests:

bash
go test -race ./cli/internal/analytics/...

The race detector will report concurrent read/write accesses to both client and cachedSyncEventDetails.