Skip to content

healthcheck: defer health check until cluster finishes warming - #43277

Merged
wbpcode merged 9 commits into
envoyproxy:mainfrom
Nordix:active-healthcheck-w-mutual-tls-auth
Mar 25, 2026
Merged

wbpcode merged 9 commits into
envoyproxy:mainfrom
Nordix:active-healthcheck-w-mutual-tls-auth

Conversation

@tsaarni

@tsaarni tsaarni commented Feb 2, 2026 •

Copy link
Copy Markdown
Member

Fixes #43116

Commit Message: healthcheck: defer health check until cluster finishes warming

Additional Description:
Active health checks started before the cluster finished initializing, causing failures when the cluster required SDS secrets for upstream connections. Health checks failed because the transport socket configuration was not ready, leading to intermittent failures at startup and when recreating the cluster to update the SDS reference, such as during certificate rotation..

See #43116 for full problem description.

This change defers the start of health checks until the cluster has finished warming, ensuring that all necessary configurations (including SDS secrets) are fetched before checks begin.

Risk Level: Low

Testing:
Added test to verify that health checks are deferred until the cluster warming state is cleared.

Docs Changes: N/A

Release Notes:
health_check: Fixed a race condition where active health checks could start before required upstream TLS SDS secrets were fetched, causing intermittent health check failures.

Platform Specific Features: N/A

@repokitteh-read-only

Copy link
Copy Markdown

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #43277 was opened by tsaarni.

see: more, trace.

@tsaarni

tsaarni commented Feb 3, 2026

Copy link
Copy Markdown
Member Author

/retest

@tsaarni
tsaarni force-pushed the active-healthcheck-w-mutual-tls-auth branch 5 times, most recently from f94b7ae to 6e4ee50 Compare February 5, 2026 14:06
Health checks were starting immediately when the health checker was
created, before the cluster completed initialization. This caused
issues when cluster depended on SDS secrets: health check sessions
would fail because the transport socket configuration wasn't ready yet.

Signed-off-by: Tero Saarni <[email protected]>
@tsaarni
tsaarni force-pushed the active-healthcheck-w-mutual-tls-auth branch from 6e4ee50 to c5ae48b Compare February 5, 2026 15:09
@tsaarni
tsaarni marked this pull request as ready for review February 5, 2026 15:15
@tsaarni

tsaarni commented Feb 5, 2026

Copy link
Copy Markdown
Member Author

Cc @yanavlasov @adisuissa

@KBaichoo

KBaichoo commented Feb 6, 2026

Copy link
Copy Markdown
Contributor

/assign @adisuissa

@adisuissa adisuissa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the fix makes sense to me, and overall LGTM.
Please add a runtime-guard as this is a behavior-visible change, and a release note.

addHosts(hosts_added);
// Skip adding hosts while cluster is still warming (e.g., waiting for SDS secrets).
// start() will add all existing hosts after warming completes.
if (cluster_.info()->configUpdateStats().warming_state_.value() == 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems a bit strange that stats are used to determine whether the cluster is active or warmed. Is there a different path that can be used here (that avoids using the stats)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was not, but I have now added the new flag HealthCheckerImplBase::started_ to track if HealthCheckerImplBase::start() has been called. Since start() is now delayed until the cluster is active, this flag effectively serves the same purpose.

void HealthCheckerImplBase::addHosts(const HostVector& hosts) {
for (const HostSharedPtr& host : hosts) {
if (host->disableActiveHealthCheck()) {
if (host->disableActiveHealthCheck() || active_sessions_.contains(host)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing this is an improvement that is not related to the current fix, correct?

@tsaarni tsaarni Feb 10, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed to make this change to prevent a new issue caused by delaying HealthCheckerImplBase::start():

When running IpVersionsClientType/LedsIntegrationTest.BasicLeds I got a crash due to the ASSERT in the health checker session destructor here.

With delayed start(), the sequence was:

  1. Host is added during cluster warming.
  2. Health checker is finally started and HealthCheckerImplBase::start() adds all current hosts by calling addHosts().
  3. HealthCheckerImplBase::onClusterMemberUpdate() is called with the same host, which calls addHosts() again.
  4. A new session is created, it replaces the old session object, and the destructor of to-be-replaced old session fails due to the ASSERT(client_ == nullptr).

Previously, before this PR, the sequence was:

  1. HealthCheckerImplBase::start() is called immediately, but there are no hosts yet, so addHosts() is not called.
  2. Host is added.
  3. HealthCheckerImplBase::onClusterMemberUpdate() is called and the session is created successfully.

Now I'm wondering if there is any state that requires recreating the session at every cluster member update, rather than skipping creation when a session already exists. I must admit, I don't understand how the client_ is released.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess HealthCheckerImplBase::addHosts() was probably never called twice for the same host before this change. Maybe instead of re-creating same host, the host always went through the HealthCheckerImplBase::onClusterMemberUpdate(..., removed_hosts) and therefore the session, including client_ was released here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have enough context here, but the fix seems OK to me as there shouldn't really be a need to make a session to the same host (assuming the previous session is already valid).
To ensure that this doesn't cause an accidental issue, it is suggested to also have this under the runtime guard.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @adisuissa, I have placed this behind the existing runtime guard in new commit 7cb86af.

@repokitteh-read-only

Copy link
Copy Markdown

CC @envoyproxy/runtime-guard-changes: FYI only for changes made to (source/common/runtime/runtime_features.cc).

🐱

Caused by: #43277 was synchronize by tsaarni.

see: more, trace.

@tsaarni

tsaarni commented Feb 11, 2026

Copy link
Copy Markdown
Member Author

Please add a runtime-guard as this is a behavior-visible change, and a release note.

@adisuissa I've now added a runtime guard to restore the old behavior and a test case for that.

@fergian94 fergian94 mentioned this pull request Feb 18, 2026
@tsaarni

tsaarni commented Feb 18, 2026

Copy link
Copy Markdown
Member Author

@adisuissa, friendly reminder, I'd appreciate your review when you have time! I've caught up with main and resolved new conflicts.

@adisuissa adisuissa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM.
/assign-from @envoyproxy/senior-maintainers

void HealthCheckerImplBase::addHosts(const HostVector& hosts) {
for (const HostSharedPtr& host : hosts) {
if (host->disableActiveHealthCheck()) {
if (host->disableActiveHealthCheck() || active_sessions_.contains(host)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have enough context here, but the fix seems OK to me as there shouldn't really be a need to make a session to the same host (assuming the previous session is already valid).
To ensure that this doesn't cause an accidental issue, it is suggested to also have this under the runtime guard.

@repokitteh-read-only

Copy link
Copy Markdown

@envoyproxy/senior-maintainers assignee is @zuercher

🐱

Caused by: a #43277 (review) was submitted by @adisuissa.

see: more, trace.

@agrawroh

Copy link
Copy Markdown
Member

@tsaarni Needs a main merge.

/wait

@tsaarni

tsaarni commented Mar 10, 2026

Copy link
Copy Markdown
Member Author

@agrawroh I've merged.

It would be great to get this forward!

@tsaarni

tsaarni commented Mar 12, 2026

Copy link
Copy Markdown
Member Author

/retest

@tsaarni

tsaarni commented Mar 16, 2026

Copy link
Copy Markdown
Member Author

/retest

@tsaarni

tsaarni commented Mar 16, 2026

Copy link
Copy Markdown
Member Author

@yanavlasov @wbpcode @phlax, I’d appreciate an additional maintainer review on this PR when you have a moment 🙏

@wbpcode wbpcode left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks.

@wbpcode
wbpcode merged commit c65fef7 into envoyproxy:main Mar 25, 2026
29 checks passed
@tsaarni

tsaarni commented Mar 25, 2026

Copy link
Copy Markdown
Member Author

Thank you @wbpcode.

fishcakez pushed a commit to fishcakez/envoy that referenced this pull request Mar 25, 2026
…proxy#43277)

Fixes envoyproxy#43116

**Commit Message:** healthcheck: defer health check until cluster
finishes warming

**Additional Description:**
Active health checks started before the cluster finished initializing,
causing failures when the cluster required SDS secrets for upstream
connections. Health checks failed because the transport socket
configuration was not ready, leading to intermittent failures at startup
and when recreating the cluster to update the SDS reference, such as
during certificate rotation..

See envoyproxy#43116 for full problem description.

This change defers the start of health checks until the cluster has
finished warming, ensuring that all necessary configurations (including
SDS secrets) are fetched before checks begin.

**Risk Level:** Low

**Testing:**
Added test to verify that health checks are deferred until the cluster
warming state is cleared.

**Docs Changes:** N/A

**Release Notes:**
health_check: Fixed a race condition where active health checks could
start before required upstream TLS SDS secrets were fetched, causing
intermittent health check failures.

**Platform Specific Features:** N/A

---------

Signed-off-by: Tero Saarni <[email protected]>
TAOXUY pushed a commit to TAOXUY/envoy that referenced this pull request Apr 1, 2026
…proxy#43277)

Fixes envoyproxy#43116

**Commit Message:** healthcheck: defer health check until cluster
finishes warming

**Additional Description:**
Active health checks started before the cluster finished initializing,
causing failures when the cluster required SDS secrets for upstream
connections. Health checks failed because the transport socket
configuration was not ready, leading to intermittent failures at startup
and when recreating the cluster to update the SDS reference, such as
during certificate rotation..

See envoyproxy#43116 for full problem description.

This change defers the start of health checks until the cluster has
finished warming, ensuring that all necessary configurations (including
SDS secrets) are fetched before checks begin.

**Risk Level:** Low

**Testing:**
Added test to verify that health checks are deferred until the cluster
warming state is cleared.

**Docs Changes:** N/A

**Release Notes:**
health_check: Fixed a race condition where active health checks could
start before required upstream TLS SDS secrets were fetched, causing
intermittent health check failures.

**Platform Specific Features:** N/A

---------

Signed-off-by: Tero Saarni <[email protected]>
Signed-off-by: Xuyang Tao <[email protected]>
citrus7 pushed a commit to citrus7/envoy that referenced this pull request Apr 1, 2026
…proxy#43277)

Fixes envoyproxy#43116

**Commit Message:** healthcheck: defer health check until cluster
finishes warming

**Additional Description:**
Active health checks started before the cluster finished initializing,
causing failures when the cluster required SDS secrets for upstream
connections. Health checks failed because the transport socket
configuration was not ready, leading to intermittent failures at startup
and when recreating the cluster to update the SDS reference, such as
during certificate rotation..

See envoyproxy#43116 for full problem description.

This change defers the start of health checks until the cluster has
finished warming, ensuring that all necessary configurations (including
SDS secrets) are fetched before checks begin.

**Risk Level:** Low

**Testing:**
Added test to verify that health checks are deferred until the cluster
warming state is cleared.

**Docs Changes:** N/A

**Release Notes:**
health_check: Fixed a race condition where active health checks could
start before required upstream TLS SDS secrets were fetched, causing
intermittent health check failures.

**Platform Specific Features:** N/A

---------

Signed-off-by: Tero Saarni <[email protected]>
Signed-off-by: Jonathan Wu <[email protected]>
nshipilov pushed a commit to nshipilov/envoy that referenced this pull request Apr 13, 2026
…proxy#43277)

Fixes envoyproxy#43116

**Commit Message:** healthcheck: defer health check until cluster
finishes warming

**Additional Description:**
Active health checks started before the cluster finished initializing,
causing failures when the cluster required SDS secrets for upstream
connections. Health checks failed because the transport socket
configuration was not ready, leading to intermittent failures at startup
and when recreating the cluster to update the SDS reference, such as
during certificate rotation..

See envoyproxy#43116 for full problem description.

This change defers the start of health checks until the cluster has
finished warming, ensuring that all necessary configurations (including
SDS secrets) are fetched before checks begin.

**Risk Level:** Low

**Testing:**
Added test to verify that health checks are deferred until the cluster
warming state is cleared.

**Docs Changes:** N/A

**Release Notes:**
health_check: Fixed a race condition where active health checks could
start before required upstream TLS SDS secrets were fetched, causing
intermittent health check failures.

**Platform Specific Features:** N/A

---------

Signed-off-by: Tero Saarni <[email protected]>
Signed-off-by: Nick Shipilov <[email protected]>
krinkinmu pushed a commit to grnmeira/envoy that referenced this pull request Apr 20, 2026
…proxy#43277)

Fixes envoyproxy#43116

**Commit Message:** healthcheck: defer health check until cluster
finishes warming

**Additional Description:**
Active health checks started before the cluster finished initializing,
causing failures when the cluster required SDS secrets for upstream
connections. Health checks failed because the transport socket
configuration was not ready, leading to intermittent failures at startup
and when recreating the cluster to update the SDS reference, such as
during certificate rotation..

See envoyproxy#43116 for full problem description.

This change defers the start of health checks until the cluster has
finished warming, ensuring that all necessary configurations (including
SDS secrets) are fetched before checks begin.

**Risk Level:** Low

**Testing:**
Added test to verify that health checks are deferred until the cluster
warming state is cleared.

**Docs Changes:** N/A

**Release Notes:**
health_check: Fixed a race condition where active health checks could
start before required upstream TLS SDS secrets were fetched, causing
intermittent health check failures.

**Platform Specific Features:** N/A

---------

Signed-off-by: Tero Saarni <[email protected]>
botengyao pushed a commit that referenced this pull request Oct 23, 2026
…de paths (#48561)

Commit Message: runtime: remove health_check_after_cluster_warming flag
and legacy code paths
Additional Description: 
The guard was added in #43277 (2026-03). This removes it and the legacy
code path, so active health checking always starts once the cluster
finishes warming rather than when the health checker is attached. The
guard-disabled integration test
ClusterWarmingWhileHealthCheckBlocksOnSdsDisabled is removed.
Risk Level: Low
Testing: N/A.
Docs Changes: N/A
Release Notes: added.
Runtime guard: Removed
envoy.reloadable_features.health_check_after_cluster_warming

---------

Signed-off-by: wbpcode <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Active health checks fail when using upstream TLS with client certificate

6 participants