Skip to content

Envoy crashes if CDS response has two clusters with the same name #3987

@ramaraochavali

Description

@ramaraochavali

When Envoy has initialized it self with a set of clusters, if a CDS update comes that has two clusters with the same name, it crashes. If the duplicate comes in the as part of the initial CDS response, it works correctly.

It crashes at this line

 if (existing_active_cluster != active_clusters_.end() ||
      existing_warming_cluster != warming_clusters_.end()) {
    // The following init manager remove call is a NOP in the case we are already initialized. It's
    // just kept here to avoid additional logic.
    init_helper_.removeCluster(*existing_active_cluster->second->cluster_);
    cm_stats_.cluster_modified_.inc();
  } else {
    cm_stats_.cluster_added_.inc();

It passes through if the condition because it has add the cluster with the same name to warming_clusters and hence it enters the if loop but since the cluster with name does not existing in the active_clusters, *existing_active_cluster->second crashes.

We could guard this removeCluster call with if (existing_active_cluster != active_clusters_.end()) to prevent this crash. This is simpler solution which I tried and it works.
Since cluster name is supposed to be unique, ideally should we validate the resource list at onConfigUpdate method of cdsapi and check for duplicates? If we introduce the validation what should be the behaviour? should we reject the entire cds response ? or simplify overwrite with the latest cluster?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions