Skip to content

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

Description

@praneshnikhar

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:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions