Skip to content

Data race in Supervisor's remoteConfig field with concurrent access #44173

@iblancasa

Description

@iblancasa

Component(s)

cmd/opampsupervisor

What happened?

The Supervisor struct's remoteConfig field is accessed concurrently without synchronization, causing a data race.

What happens:

  1. The remoteConfig field (*protobufs.AgentRemoteConfig) is read and written from multiple goroutines:

    • Written in processRemoteConfigMessage() when receiving config from the OpAMP server
    • Written in loadRemoteConfig() during initialization
    • Read in composeMergedConfig() calls from multiple places (loadAndWriteInitialMergedConfig(), setupOwnTelemetry(), processRemoteConfigMessage(), processAgentIdentificationMessage())
    • Read in saveAndReportConfigStatus() to get the config hash
  2. Concurrent access can occur when:

    • A new remote config arrives while the supervisor is composing a merged config
    • The supervisor is reading remoteConfig while another goroutine updates it
    • Multiple goroutines access remoteConfig simultaneously
  3. This leads to:

    • Data races detected by the race detector
    • Potential nil pointer dereferences if a read happens during a write
    • Undefined behavior from reading partially written values

Additional context:

The saveAndReportConfigStatus() method accesses s.remoteConfig.GetConfigHash() without checking if remoteConfig is nil, which can cause a panic if accessed before any remote config is received.

Collector version

380f40a

Environment information

No response

OpenTelemetry Collector configuration

Log output

Additional context

No response

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions