#38329·wazuh

https_client component tests: intermittent startup hang under valgrind fails the RTR memory stage

Author: jr0meCreated Aug 12, 2026Updated Oct 1, 2026
Labelstype/bugtype/testlevel/task
Wazuh version Component Install type Install method Platform
5.0.0-rc1 (5.0.0-https) Agent — client-agent/https_client component tests Agent Sources Ubuntu 24.04 x86_64, valgrind-3.22.0, GCC 13

Description

FacadeE2eTest.AHeldStatefulRequestDoesNotStallStatelessOrControl intermittently fails under valgrind, which fails the RTR memory stage for client-agent/https_client ([https_client_component_test : FAILED]) and therefore the whole rtr (client-agent/https_client, agent) check.

It is worth being precise about what this is not, because the stage is named "valgrind" and the failure looks like a leak report:

definitely lost:   0 bytes
indirectly lost:   0 bytes
memcheck errors:   0        (no invalid read/write, no uninitialised values)
possibly lost:    70 records   <- fewer than 5.0.0-https, which has 76 and exits 0
still reachable: 18419 records <- not errors by default

The non-zero exit comes from a gtest failure inside the valgrind run, not from memory. The failing assertion is the startup wait:

facadeE2e_component_test.cpp:530: Failure
Value of: waitFor(recorder.startupCount, 1, 3000)
  Actual: false
Expected: true
[  FAILED  ] FacadeE2eTest.AHeldStatefulRequestDoesNotStallStatelessOrControl (34521 ms)

hc_start() is called, and the on_startup_result callback never fires within the deadline.

Reproduction

bash
cd src
make deps TARGET=agent -j$(nproc)
make TARGET=agent DEBUG=1 TEST=1 VALGRIND=1 -j$(nproc)
cd build/bin
valgrind --leak-check=full --show-leak-kinds=all -q --error-exitcode=1 ./https_client_component_test

Reproduces roughly 1 run in 3–5. It does not reproduce with --gtest_filter on that test alone.

Observations

scenario result
full 38-test suite under valgrind, 5.0.0-https passed (38/38), 140 s
full suite under valgrind, with PR #38320 1 failure in 3 runs
full suite under valgrind, startup bound raised 3 s → 10 s 1 failure in 4 runs — no improvement
that test alone under valgrind passes: 8.5 s, 10.7 s (and 12.9 s, 10.9 s on 5.0.0-https)
that test without valgrind passes in 1.2 s

The failure is not specific to #38320 — that PR does not touch this file, and the branch is faster than the base when the test runs in isolation. It is the same test binary and the same test that passes most runs.

Raising the deadline does not help, and that is the useful clue

The first thing tried was the obvious one: startup had the tightest bound in the file (3 s, so 30 s once scaledTimeout() multiplies by 10 under valgrind) while every other wait in the same test gets 4–10 s. All 14 startup waits were raised to 10 s (100 s scaled). It still failed:

run1 exit 0   38 passed   (109 s)
run2 exit 0   38 passed   (106 s)
run3 exit 1   FAILED ... AHeldStatefulRequestDoesNotStallStatelessOrControl (105607 ms)
run4 exit 0   38 passed   (118 s)

It consumed the entire 100 s budget instead of the old 30 s and still never saw startup. So startup is not slow, it makes no progress at all for over 100 seconds. That change was reverted; it only delays how long the failure takes to report.

Ruled out

  • A leak. Zero definitely/indirectly lost, zero memcheck errors, and fewer possibly-lost records than the base.
  • The /stateful hold gate. Only POST /stateful waits on the hold file (fakeManager.hpp), and the gate is only relevant after startup has already succeeded.
  • Stale listeners or leftover forked managers. Nothing bound in the 44861–44875 range and no surviving test processes between runs.
  • A too-tight deadline. See above.

Hypothesis

Thread starvation caused by threads that outlive their test, amplified by valgrind serializing execution.

Valgrind runs only one thread at a time and switches on its own schedule; with the default policy a thread can wait a long time for the CPU. Meanwhile this binary accumulates client threads: the file's own comment notes that an ASSERT_ between hc_start() and hc_destroy() returns from the test body with the handle's threads, curl handles and OpenSSL state still live (HandleGuard was introduced for exactly that). If any test leaves threads running — through an early return, a detached worker, or an intake socket thread hc_destroy() does not join — the runnable-thread count climbs test by test.

That predicts precisely what is observed: fine in isolation, fine early in the suite, and occasionally fatal for a newly started client late in the run, because its startup thread has to be scheduled at all before the callback can fire. It also explains why a bigger timeout changes nothing — the thread is not slow, it is not being run.

A second candidate that the same experiments would distinguish: a lost wakeup in the client's startup/retry path (a condition-variable signal raced past a wait) that only shows up under the extreme scheduling skew valgrind produces.

Proposed way to prove it

  1. Cheapest and nearly decisive — change only the scheduler. Re-run the full suite with valgrind --fair-sched=yes (round-robin scheduling instead of the default). If ~10 runs go green with no code change, starvation is confirmed and the lost-wakeup theory is largely excluded, since fair scheduling does not fix a missed signal.

  2. Count the threads. Add a SetUp/TearDown hook that records the live thread count (entries under /proc/self/task) per test and prints it. If the count climbs monotonically across the 38 tests instead of returning to a baseline after each hc_destroy(), threads are outliving their tests, and the specific test whose count fails to return identifies the leaker.

  3. Show it tracks position, not content. Run the failing test preceded by an increasing number of other tests via --gtest_filter to find the point where it starts failing. If failure depends on how many tests ran first rather than which ones, that is accumulation rather than an interaction with one particular predecessor.

  4. If confirmed, the fix belongs in teardown, not in the deadlines: make hc_destroy() join every thread it starts, and assert in the fixture that the thread count returns to its baseline so a future leak fails loudly and immediately instead of surfacing as an unrelated flaky test. Adding --fair-sched=yes to the RTR valgrind stage would be a reasonable belt-and-braces change but should not be the only one.

Impact

Any PR touching client-agent/https_client can hit a red rtr (client-agent/https_client, agent) check for reasons unrelated to its changes, and the failure presents as a memory problem when it is not one. Seen on #38320.