Skip to content

Active health checks fail when using upstream TLS with client certificate #43116

Closed

Description

@tsaarni

Description:

Prerequisites:

  • The cluster has a TLS transport socket configured for upstream connections.
  • The TLS transport socket references a client certificate via SDS.
  • The cluster has active health checking enabled.

All of these must be true for the bug to happen. If removing any of them, the problem goes away.

Control plane (Contour) uses basic xDS with SotW updates (separate gRPC streams for each resource type).

The Problem:

The upstream service is unavailable for certain period of time:

  • Scenario 1: The client gets a 503 Service Unavailable "no healthy upstream" error for 4 minutes after Envoy restarts
    • This is counted from the moment Envoy is back up and ready with all configuration from XDS. It doesn't include the time Envoy takes to be ready serve requests.
    • The downtime lasts for healthy_threshold * no_traffic_interval (for example: 4 * 60s = 4min).
  • Scenario 2: The client gets a 503 Service Unavailable "no healthy upstream" error for several seconds after rotating the Envoy client certificate.
    • The downtime lasts for healthy_threshold * interval seconds (for example: 4 * 5s = 20s).

I don't know exactly which Envoy versions are affected, but this isn't just a problem in the newest code. It's not specific to any recent version.

I do not have a complete understanding of the root cause yet, but the issue appears to be related to the order in which xDS resources are delivered and processed. Envoy handles the request forwarding correctly regardless the delivery order. However, active health checks fail if the SDS secret isn't ready when the cluster and endpoints are created. This happens even if the secrets arrive just a few milliseconds later. It seems there isn't any special retry logic for this. Instead, it just acts like the upstream host is actually down.

My current theory is as follows:

Scenario 1: 4 minutes of unavailability after Envoy restart

Envoy is restarted and it connects to the xDS server to fetch its configuration:

  1. Cluster is created via CDS with:
    • Active health checking enabled
    • TLS transport socket with SDS-referenced client certificate
  2. Cluster endpoints are added via EDS
  3. Health checker is started
    • Endpoints are marked unhealthy because the SDS secret is not yet available
  4. SDS discovery request is sent by Envoy and the secret is delivered by the control plane
  5. Cluster enters warming state and it starts sending health check probes
    • Upstream respond with success and probes succeed
    • Upstream remains unhealthy until healthy_threshold * no_traffic_interval (for example: 4 * 60s = 4min)
  6. Cluster becomes healthy and client requests start to succeed

During this time (about 4 minutes) traffic is rejected with 503 Service Unavailable "no healthy upstream".

Note: If triggering a cluster update during this period, then upstream becomes available again immediately.

Scenario 2: 20 seconds of unavailability after client certificate rotation

The cluster is updated with a new SDS secret reference due to certificate rotation:

  1. Cluster is updated via CDS with
    • Active health checking enabled
    • TLS transport socket with new SDS reference
  2. Old cluster is removed and new cluster is created
  3. There is no EDS update since endpoints remain the same
  4. Client requests still succeed for a while (~6 seconds but it varies)
  5. Health checker for new cluster is started
    • Endpoints are marked unhealthy because the SDS secret is not yet available
    • Client requests start to fail with 503 Service Unavailable "no healthy upstream"
  6. New SDS secret is delivered
  7. Cluster re-enters warming state and it starts sending health check probes
    • Upstream respond with success and probes succeed
    • Upstream remains unhealthy until healthy_threshold * interval (for example: 4 * 5s = 20s)
  8. Cluster becomes healthy and client requests start to succeed

During this time (about 20 seconds) traffic is rejected with 503 Service Unavailable "no healthy upstream".

Repro steps:

It's hard to provide steps to reproduce this, as it requires XDS server code. You can find the steps for Contour here: projectcontour/contour#7384.

Admin and Stats Output:

Stats are included in attached logs.

Config:

See the XDS gRPC captures attached below.

Logs:

I'm attaching gRPC captures taken from control plane side of the xDS connection (Contour) using my own capture tool. They can be viewed just as plain json file or with the browser based grpc-json-sniffer app.

Activity

  1. added
    triage
    on Jan 22, 2026
  2. tsaarni commented on Jan 22, 2026

    @tsaarni
    MemberAuthor

    I've been able to avoid the problems by adding a 1-second delay to the health check, but this is of course a hack and not the right fix.

    diff --git a/source/extensions/health_checkers/common/health_checker_base_impl.cc b/source/extensions/health_checkers/common/health_checker_base_impl.cc
    index 3923e1eaba..7bd8b3c050 100644
    --- a/source/extensions/health_checkers/common/health_checker_base_impl.cc
    +++ b/source/extensions/health_checkers/common/health_checker_base_impl.cc
    @@ -427,6 +427,15 @@ HealthCheckerImplBase::ActiveHealthCheckSession::clearPendingFlag(HealthTransiti
     }
    
     void HealthCheckerImplBase::ActiveHealthCheckSession::onIntervalBase() {
    +  auto& factory = host_->transportSocketFactory();
    +  if (factory.implementsSecureTransport() && factory.sslCtx() == nullptr && !tls_deferred_check_) {
    +    ENVOY_LOG(debug, "TLS secret is not ready yet for host {}, deferring first health check",
    +              host_->address()->asString());
    +    tls_deferred_check_ = true;
    +    interval_timer_->enableTimer(std::chrono::seconds(1));
    +    return;
    +  }
    +
       onInterval();
       timeout_timer_->enableTimer(parent_.timeout_);
       parent_.stats_.attempt_.inc();
    diff --git a/source/extensions/health_checkers/common/health_checker_base_impl.h b/source/extensions/health_checkers/common/health_checker_base_impl.h
    index 528ef88cb8..5ba76b1164 100644
    --- a/source/extensions/health_checkers/common/health_checker_base_impl.h
    +++ b/source/extensions/health_checkers/common/health_checker_base_impl.h
    @@ -90,6 +90,7 @@ protected:
         uint32_t num_unhealthy_{};
         uint32_t num_healthy_{};
         bool first_check_{true};
    +    bool tls_deferred_check_{false};
         TimeSource& time_source_;
       };
    
  3. yanavlasov commented on Jan 23, 2026

    @yanavlasov
    Contributor

    Thanks for the analysis. I would think that Envoy should keep clusters in the warming state until SDS config is delivered and not mark endpoints unhealthy before that.

    Is this is an issue with just Contour? did you try reaching out to them to see what they might suggest?

    @adisuissa ^^^

  4. tsaarni commented on Jan 23, 2026

    @tsaarni
    MemberAuthor

    Is this is an issue with just Contour? did you try reaching out to them to see what they might suggest?

    I'm maintainer in Contour project myself. I think this applies to any control plane, at least the ones using basic XDS with SotW and use active health check with client secret via SDS.

  5. adisuissa commented on Jan 23, 2026

    @adisuissa
    Contributor

    Thanks for the analysis. I would think that Envoy should keep clusters in the warming state until SDS config is delivered and not mark endpoints unhealthy before that.

    +1.
    Keeping the clusters in warming state until the secrets are retrieved should probably be the right thing to do. I'm guessing the issue is that the health-checking is performed before the cluster is marked active.
    I'm not sure what initiates the health-checking, but I think the first thing is to create a repro integration test based on either eds_integration_test or one of the sds integrations tests (dynamic or static).

  6. added
    area/sds
    and removed
    triage
    on Jan 27, 2026
  7. tsaarni commented on Feb 2, 2026

    @tsaarni
    MemberAuthor

    I submitted a draft for suggested fix #43277.

  8. github-actions commented on Mar 4, 2026

    @github-actions

    This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or "no stalebot" or other activity occurs. Thank you for your contributions.

  9. added
    stale
    on Mar 4, 2026
  10. github-actions commented on Mar 12, 2026

    @github-actions

    This issue has been automatically closed because it has not had activity in the last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted" or "no stalebot". Thank you for your contributions.

  11. added a commit that references this issue on Mar 25, 2026
    c65fef7
  12. added a commit that references this issue on Mar 25, 2026
    23a60f8
  13. added a commit that references this issue on Apr 1, 2026
    a7b52ba
  14. added a commit that references this issue on Apr 1, 2026
    76623a6
  15. added a commit that references this issue on Apr 13, 2026
    2c1422f
  16. added a commit that references this issue on Apr 20, 2026
    32ee984
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

    area/sdsarea/tlsbugstale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions