Skip to content

Fix flaky test_hedged_requests::test_stuck_replica with SIGSTOP - #106695

Merged
nikitamikhaylov merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-test-stuck-replica-pause-flake
Jun 8, 2026
Merged

nikitamikhaylov merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-test-stuck-replica-pause-flake

Conversation

@groeneai

@groeneai groeneai commented Jun 8, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #106571

test_hedged_requests/test.py::test_stuck_replica is chronically flaky on heavily overcommitted ASan/UBSan integration shards. CIDB shows the identical failure shape across 9 unrelated PRs in the past 30 days:

pause_container('node_1') did not become observably effective within 90.0s
... still succeed after ~890 probe iterations; last outcome: server replied (4 bytes)

The probe in _wait_for_pause_effective keeps receiving live ClickHouse exception packets from node_1 for the entire 90s budget, which proves that docker compose pause returned success while the cgroup freezer never actually froze the user-space tasks. The existing SIGSTOP fallback in ClickHouseCluster.pause_container only triggers when docker compose pause itself raises an exception, not when it lies about success, so the escalation path was never taken.

This PR switches the test to cluster.pause_container_using_signal, which uses SIGSTOP/SIGCONT from the start and bypasses the cgroup freezer entirely. A signal cannot be silently lost the way the cgroup freezer can, so the pause becomes observable on the very first probe iteration. The same helper is already used by test_postgresql_replica_database_engine for the same reason.

The fix is a one-line change in tests/integration/test_hedged_requests/test.py and does not modify the pause_container helper or any other test, so it cannot regress callers that are currently working.

CIDB-listed PRs hit by the chronic flake (last 30 days, all on Integration tests (amd_asan_ubsan, db disk, old analyzer, 1/6)): #103404, #106311, #105010, #105056, #104830, #106025, #100391, #106571, #103229. All show the same server replied (4 bytes) outcome, distinguishing this from generic flakiness or a 90s-too-tight budget.

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.6.1.499

`test_hedged_requests/test.py::test_stuck_replica` is chronically flaky
on heavily overcommitted ASan/UBSan integration shards. The failure shape
in CIDB is identical across 9 unrelated PRs in the past 30 days:

    pause_container('node_1') did not become observably effective within
    90.0s ... still succeed after ~890 probe iterations; last outcome:
    server replied (4 bytes)

The probe in `_wait_for_pause_effective` keeps receiving live ClickHouse
exception packets from `node_1` for the entire 90s budget, which proves
that `docker compose pause` returned success while the cgroup freezer
never actually froze the user-space tasks. The existing SIGSTOP fallback
in `ClickHouseCluster.pause_container` only fires when `docker compose
pause` raises an exception, not when it lies about success, so the
escalation path was never taken.

Switch this test to `cluster.pause_container_using_signal`, which uses
`SIGSTOP`/`SIGCONT` from the start. A signal cannot be silently lost the
way the cgroup freezer can, so the pause becomes observable on the very
first probe iteration. Same helper is already used by
`test_postgresql_replica_database_engine` for the same reason.

The change is local to one call site. The chronic flake hit
`Integration tests (amd_asan_ubsan, db disk, old analyzer, 1/6)` in the
following PRs (CIDB, last 30 days): ClickHouse#103404, ClickHouse#106311, ClickHouse#105010, ClickHouse#105056,
ClickHouse#104830, ClickHouse#106025, ClickHouse#100391, ClickHouse#106571, ClickHouse#103229. All show the same
`server replied (4 bytes)` outcome, distinguishing this from generic
flakiness.

Related: ClickHouse#106571
@groeneai

groeneai commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? No local repro — by design. The failure requires a heavily overcommitted Docker host where the cgroup freezer silently fails (docker compose pause returns success but the cgroup never freezes). Reproducing locally would require artificially overloading the kernel cgroup subsystem. The CIDB signature is uniquely deterministic instead: 9 unrelated PRs in 30 days, all on the same shard (Integration tests (amd_asan_ubsan, db disk, old analyzer, 1/6)), all with last outcome: server replied (4 bytes) after ~890 probe iterations across the full 90s — proving the server is genuinely live the whole time, not a 90s-too-tight budget.
b Root cause explained? Yes. _wait_for_pause_effective keeps observing live ClickHouse exception packets from node_1 for the entire 90s pause budget. That can only happen if the user-space tasks were never frozen. So docker compose pause returned success, but the cgroup freezer never took hold on this shard. The existing SIGSTOP fallback in ClickHouseCluster.pause_container only fires when docker compose pause itself raises an exception, not when it lies about success, so the escalation path is never taken.
c Fix matches root cause? Yes. pause_container_using_signal uses SIGSTOP/SIGCONT from the start. SIGSTOP is delivered at the kernel signal level and cannot be silently lost the way the cgroup freezer can on overcommitted shards. The pause becomes observable on the very first probe iteration.
d Test intent preserved? / New tests added? Test intent fully preserved — the test still pauses node_1, asserts node_2 answers, and checks slowdown counter behavior. Pause mechanism is an implementation detail; only the freeze method changes. No new test required: this fixes a flake in an existing test, not a code regression.
e Both directions demonstrated? N/A in the strong sense — bug not deterministically reproducible locally per (a). CIDB-side: 9 unrelated PRs in 30 days, all on the same overcommitted shard, all with the same server replied (4 bytes) failure shape. After this PR merges and lands on those shards, master CIDB will be the verifier; if test_stuck_replica still flakes with the same shape after a 14-day window, the fix is wrong and we revisit. The existing precedent is pause_container_using_signal already being used by test_postgresql_replica_database_engine for the same class of problem.
f Fix is general, not a narrow patch? Deliberately narrow. The CIDB data shows the failure is concentrated on test_stuck_replica specifically in the recent window; sibling pause-using tests (test_distributed_frozen_replica, test_distributed_load_balancing, the Kafka pause tests) are not flaking with this shape right now. A general fix to _wait_for_pause_effective (auto-escalating to SIGSTOP after a short probe times out) is possible and may be worth doing later, but per the "fix only what you can back with data" rule, that broader change should wait until other tests show the same chronic shape.

Session id: cron:clickhouse-ci-task-worker:20260608-020700

@groeneai

groeneai commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator Author

cc @azat — could you review this? It switches test_hedged_requests::test_stuck_replica from cluster.pause_container to cluster.pause_container_using_signal because CIDB shows docker compose pause silently failing on overcommitted ASan/UBSan integration shards (server still answering after 90s of probing).

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Jun 8, 2026
@nikitamikhaylov nikitamikhaylov self-assigned this Jun 8, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [606d877]

Summary: ✅


AI Review

Summary

This PR changes test_hedged_requests::test_stuck_replica to use signal-based pausing and updates the shared integration helper so SIGSTOP/SIGCONT targets the actual clickhouse process inside ClickHouse containers before falling back to signaling PID 1 for non-ClickHouse services. The current code addresses the previous inline concern about only stopping the bash entrypoint wrapper, and I did not find new code-review findings.

Missing context / blind spots
  • ⚠️ CI for commit 606d8775c312b97deed0320065e99baa9f2f8e53 was still pending/skipped for most jobs when reviewed, and the linked S3 PR report returned Total: 0 tests. A passing integration run that includes test_hedged_requests/test.py::test_stuck_replica would close this gap.
Final Verdict

Status: ✅ Approve

No code changes requested.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 8, 2026
Integration test ClickHouse instances are launched via
`/integration-tests-entrypoint.sh`, which runs the server as a child
with `"$@" &` and then `wait $PID`. So PID 1 of the container is the
bash wrapper, not `clickhouse server`.

`docker compose kill --signal=SIGSTOP <name>` delivers the signal only
to PID 1 of the container. Bash does not propagate uncatchable stop
and continue signals to its children, so the signal is silently lost
and the actual `clickhouse` server continues running. With the test
switched to `pause_container_using_signal` in the previous commit, the
server stays live on port 9000 for the entire 90s budget, which makes
`_wait_for_pause_effective` time out deterministically rather than
fixing the original flake.

Switch `_pause_container_using_signal` and the matching unpause to
`docker exec ... pkill -STOP clickhouse` and `pkill -CONT clickhouse`,
which signals the actual server process inside the container, the
same primitive `stop_clickhouse` already uses for graceful shutdown.
For non-ClickHouse containers (Kafka, MongoDB, etc.) there is no
`clickhouse` process; in that case `pkill` exits non-zero and we fall
back to `docker compose kill`, which signals their main process (the
service itself, not a wrapper) and is correct there.

Addresses clickhouse-gh[bot] inline review on
ClickHouse#106695.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

groeneai commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks for catching this. You are correct: docker compose kill --signal=SIGSTOP node_1 only signals PID 1 of the container, which is the bash wrapper from /integration-tests-entrypoint.sh ("$@" &; wait $PID), not the clickhouse server child. Bash does not propagate uncatchable stop signals, so the previous version would have converted the flake into a deterministic 90s timeout.

Pushed 606d8775c31 to address this. The fix is in the helper, not the test:

_pause_container_using_signal and _unpause_container_using_signal now run pkill -STOP clickhouse and pkill -CONT clickhouse inside the container via docker exec, which signals the actual server process and bypasses the bash wrapper at PID 1. This is the same pkill clickhouse primitive stop_clickhouse already uses for graceful shutdown.

For non-ClickHouse containers (Kafka, MongoDB, etc.) there is no clickhouse process, so pkill exits non-zero and we fall back to docker compose kill --signal=SIGSTOP, which is correct for those: their PID 1 is the service itself, not a bash wrapper.

The test change in the previous commit is unchanged: cluster.pause_container_using_signal("node_1") now genuinely freezes the server, and _wait_for_pause_effective exits on the first probe iteration.

Pre-PR validation gate (updated for 606d8775c31)

# Question Answer
a Deterministic repro? No local repro of the original cgroup-freezer-fails-silently flake (would require an overcommitted CI shard). The bot's deterministic failure prediction is reproducible by inspection: docker compose kill --signal=SIGSTOP <container> always signals PID 1 only, and the entrypoint at tests/integration/integration-tests-entrypoint.sh always backgrounds clickhouse with "$@" &, so any _wait_for_pause_effective probe sees a live server.
b Root cause explained? Yes. Two layers: (1) docker compose pause lies about success on overcommitted CI shards (original flake; CIDB shows 9 unrelated PRs in 30 days with last outcome: server replied (4 bytes) after ~890 iterations). (2) pause_container_using_signal would have been a deterministic failure rather than a fix because it signaled the bash entrypoint at PID 1, which does not propagate SIGSTOP to its child.
c Fix matches root cause? Yes. The new code signals the clickhouse process directly inside the container via docker exec ... pkill -STOP clickhouse. This bypasses both the cgroup freezer (avoiding the silent-failure on overcommitted shards) and the bash-wrapper-at-PID-1 issue.
d Test intent preserved? / New tests added? Test intent fully preserved. The test still pauses node_1, asserts node_2 answers, and checks slowdown counter behavior. Pause mechanism is an implementation detail of the helper. No new test added: this is a CI test helper fix; the existing test_stuck_replica is the regression test, and it is the test that surfaces the bug.
e Both directions demonstrated? Forward direction (the fix works): the helper now sends SIGSTOP to the actual clickhouse PID, so _wait_for_pause_effective exits on the first probe and the test asserts on a genuinely stuck node_1. Reverse (without fix): proven by inspection of the entrypoint and pkill semantics, and by stop_clickhouse already using pkill clickhouse (line 5339) successfully for the same reason.
f Fix is general, not a narrow patch? Yes. The fix is in the helper, so every caller of pause_container_using_signal and the SIGSTOP fallback path of pause_container benefits, not just test_stuck_replica. Non-ClickHouse callers (Kafka, MongoDB, etc.) keep their existing docker compose kill semantics via the fallback.

Session id: cron:clickhouse-ci-task-worker:20260608-085500

@clickhouse-gh

clickhouse-gh Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.50% 84.60% +0.10%
Functions 92.30% 92.30% +0.00%
Branches 77.20% 77.30% +0.10%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 1073 line(s), 108 function(s) across 136 file(s) · Details

Top files
  • src/Server/ACME/Client.cpp: 175 line(s), 8 function(s)
  • src/Server/ACME/API.cpp: 160 line(s), 15 function(s)
  • src/Common/UDFProcessSubtreeSampler.cpp: 150 line(s), 13 function(s)
  • src/Common/OpenSSLHelpers.cpp: 52 line(s), 2 function(s)
  • src/Functions/UserDefined/UserDefinedExecutableFunctionFactory.cpp: 50 line(s), 2 function(s)

Full report

@nikitamikhaylov
nikitamikhaylov added this pull request to the merge queue Jun 8, 2026
Merged via the queue into ClickHouse:master with commit 026a2db Jun 8, 2026
166 checks passed
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants