Skip to content

race condition in DispatcherImpl #6699

@mergeconflict

Description

@mergeconflict

There is a race condition in DispatcherImpl, between this write in initializeStats on the main thread:

stats_prefix_ = prefix + "dispatcher";

and this read in run on the worker threads:

if (!stats_prefix_.empty())

Disconcertingly, this wasn't caught by our tsan build, so it is not easy to reproduce. @AndresGuedez caught this when trying to do our weekly import at Google.

The code is written this way because it's important to log the thread ID corresponding to the worker's stat prefix for debugging:

if (!stats_prefix_.empty()) {
  ENVOY_LOG(debug, "running {} on thread {}", stats_prefix_, run_tid_->debugString());
}

I'm sort of hesitant to introduce a mutex just for this -- it feels like we just shouldn't be splitting this work across threads this way at all -- I think the correct fix is just to ensure that stats are initialized on the dispatcher's thread, at which point we have a thread id.

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