Skip to content

Add SIGKILL fallback in test_keeper_zookeeper_converter::stop_zookeeper - #103600

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-keeper-zookeeper-converter-sigkill
Apr 28, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-keeper-zookeeper-converter-sigkill

Conversation

@groeneai

@groeneai groeneai commented Apr 27, 2026 •

Copy link
Copy Markdown
Collaborator

Per directive at #100941 (comment)
(fix test_keeper_zookeeper_converter/test.py::test_acls[True] flakiness in a separate PR).

zkServer.sh stop in the ZooKeeper 3.6.3 binary used by the test sends a single
SIGTERM to the JVM, removes the PID file, and returns — it does not wait for
the JVM to actually exit and has no SIGKILL fallback (see zkServer.sh upstream).
The test's stop_zookeeper polls pgrep for up to 60 seconds and raises
Failed to stop ZooKeeper in 60 secs if the JVM has not finished its shutdown
hooks by then.

Under sanitizer-heavy CI builds (MSan in particular), the ZooKeeper JVM and the
MSan-instrumented ClickHouse server share the same Docker container and the
same CPU. MSan only instruments compiled C/C++ code at the LLVM IR level — the
JVM itself is not sanitizer-instrumented, the OpenJDK java binary and the
ZooKeeper bytecode run the same way they do in non-sanitizer builds. But the
~2–10× CPU slowdown MSan adds to ClickHouse leaves the JVM with much less
scheduler share. JVM shutdown hooks (log flushes, snapshot finalization, file
close, ZK-internal teardown) are largely synchronous, and under that scheduler
pressure they can occasionally exceed the 60-second pgrep poll. This is the
dominant chronic-flakiness mode this test exhibited before #102492 (the
pgrep regex fix and start_zookeeper retry loop).

Recent CIDB shows zero test_acls failures across ~27,000 runs in the 8 days
since #102492 merged, but the historical pattern is sporadic and sanitizer
load can push JVM shutdown over the 60s line at any time.

The genuine ZooKeeper JVM in this test exists only to populate test data for
the clickhouse keeper-converter tool — we do not test the JVM itself and a
clean shutdown is unnecessary. Add a SIGKILL fallback that fires after SIGTERM
does not stop the JVM in 60 seconds, so the test can never fail on a slow or
hung JVM shutdown. The bracket trick [o]rg.apache.zookeeper.server in the
pgrep / pkill pattern is preserved (and now factored into a constant) to
keep the kill from matching its own shell process.

CIDB sample failures showing the addressed pattern:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=00ecef1c87cfebeb52a024307b0a76a68518fb53&name_0=MasterCI&name_1=Integration%20tests%20%28amd_msan%2C%206%2F6%29

Verification

  • python3 -m ci.praktika run "integration" --test "test_keeper_zookeeper_converter/test.py::test_acls" --count 3 — 6/6 passes locally.
  • Direct SIGKILL mechanism check inside clickhouse/integration-test:latest:
    • pgrep -f '[o]rg\.apache\.zookeeper\.server' matches the running JVM.
    • pkill -9 -f '[o]rg\.apache\.zookeeper\.server' kills the JVM and does not match itself.
    • After the kill, pgrep returns nothing.

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.5.1.148

…LL fallback

`zkServer.sh stop` in ZooKeeper 3.6.3 only sends a single SIGTERM, removes
the PID file, and returns — it neither waits for the JVM to actually exit
nor escalates to SIGKILL. The test's `stop_zookeeper` therefore polled
`pgrep` for up to 60 seconds and raised
`Failed to stop ZooKeeper in 60 secs` if the JVM had not finished its
shutdown hooks by then.

Under sanitizer-heavy CI builds (MSan in particular) JVM shutdown hooks
can occasionally exceed 60 seconds, leading to chronic flakiness on
master and PR runs (cf. PR ClickHouse#102492 which fixed the broken `pgrep` regex
and added retries to `start_zookeeper`).

The genuine ZooKeeper JVM in this test exists only to populate test
data for the `clickhouse keeper-converter` tool — we do not test the JVM
itself and a clean shutdown is unnecessary. Add a SIGKILL fallback that
fires after SIGTERM does not stop the JVM in 60 seconds, so the test
can never fail on a slow or hung JVM shutdown. The bracket trick
`[o]rg.apache.zookeeper.server` in the `pgrep` / `pkill` pattern is
preserved to keep the kill from matching its own shell process.

Recent CI runs after PR ClickHouse#102492 (merged 2026-04-19): zero failures of
either `test_acls[True]` or `test_acls[False]` over ~27000 runs in 8 days.
This change is a proactive hardening so future sanitizer load can never
regress that streak.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate (session id: cron:clickhouse-ci-task-worker:20260427-091500)

a) Deterministic repro? No deterministic repro exists today — the test has been clean for 8 days since #102492 merged (~27,000 runs, zero failures). This PR is proactive hardening of the same fragile shutdown path that produced the chronic Failed to stop ZooKeeper in 60 secs failures before #102492.

b) Root cause explained? Yes. ZooKeeper 3.6.3's zkServer.sh stop sends a single SIGTERM via the PID file, removes the PID file, and returns. There is no built-in wait for JVM exit and no SIGKILL fallback. Under sanitizer-heavy builds (especially MSan) JVM shutdown hooks can occasionally take longer than the 60s test budget, and the pre-#102492 flakiness pattern (e.g. PR #100332 with 36 hits, PR #102492's own pre-merge runs with 14 hits) showed exactly that mode.

c) Fix matches root cause? Yes. The fix adds a SIGKILL escalation after the existing 60s SIGTERM wait, which is exactly the missing piece in zkServer.sh stop. It does not change behaviour in the happy path.

d) Test intent preserved? Yes. The genuine ZooKeeper JVM is only there to populate test data for clickhouse keeper-converter — the test does not assert anything about the JVM's shutdown semantics, so a hard kill after a hung shutdown is safe. No assertions are weakened, no no-random-* tags added, no data sizes reduced.

e) Demonstrated in both directions? Partial. I cannot reproduce the original failure locally without an MSan binary (the failure was load-induced and stopped reproducing 8 days ago), but I verified the new SIGKILL path independently inside clickhouse/integration-test:latest: pgrep -f '[o]rg\.apache\.zookeeper\.server' correctly identifies the JVM, pkill -9 -f '[o]rg\.apache\.zookeeper\.server' kills it, and the [o]rg bracket trick keeps pkill from matching its own argv. The happy path is verified by --count 3 (6/6 pass) and the existing CIDB streak.

f) Fix is general, not a narrow patch? Yes. The same stop_zookeeper function is used by every test entry point (restart_and_clear_zookeeper, restart_zookeeper, generate_zk_snapshot, copy_zookeeper_data, get_genuine_zk retry loop) — the SIGKILL fallback covers all of them. The sister test test_keeper_snapshot_small_distance has a different (less robust) stop_zookeeper that does not even wait for JVM exit; that is out of scope here and not on the directive.

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @alexey-milovidov @CurtizJ @azat — could you review this? Per @alexey-milovidov's directive on #100941 (comment) to fix test_keeper_zookeeper_converter::test_acls[True] flakiness. Adds a SIGKILL fallback in stop_zookeeper so a slow / hung ZK JVM shutdown can never time the test out. Test-only change; no production code touched.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Apr 27, 2026
@clickhouse-gh

clickhouse-gh Bot commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f38816d]

Summary: ✅


AI Review

Summary

This PR hardens test_keeper_zookeeper_converter shutdown logic by adding a SIGKILL fallback when ZooKeeper does not exit after SIGTERM within 60 seconds, reducing flakiness in sanitizer-heavy CI. The change is scoped to integration-test helper logic and looks correct; no blocker or major issues were identified.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ➖
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Apr 27, 2026
@antonio2368

Copy link
Copy Markdown
Member

Under sanitizer-heavy CI builds (MSan in particular) JVM shutdown hooks can occasionally exceed 60 seconds,

@groeneai how is JVM connected to our MSan builds?

@groeneai

Copy link
Copy Markdown
Collaborator Author

@antonio2368 good catch — that wording is imprecise, sorry. The mechanism is CPU/scheduling pressure, not direct instrumentation:

  • MSan only instruments compiled C/C++ at LLVM IR level. It does not instrument the JVM — the OpenJDK java binary is unmodified and ZooKeeper bytecode runs the same way it does in non-sanitizer builds.
  • In this integration test the ZK JVM runs in the same Docker container as the MSan-built ClickHouse server, sharing the same CPU. The MSan-instrumented server is ~2–10× slower CPU-wise.
  • When zkServer.sh stop sends SIGTERM, the JVM starts running its shutdown hooks (log flushes, snapshot finalization, file close, ZK-internal teardown). Those are largely synchronous and gated by I/O and scheduler share.
  • Under the heavy ClickHouse-side load MSan adds, the JVM can lose enough scheduler share that shutdown hooks stretch past the test's 60-second pgrep poll, and we get Failed to stop ZooKeeper in 60 secs.

So the path is indirect: MSan slows ClickHouse → ClickHouse starves the co-scheduled JVM → JVM shutdown stretches past 60 s. The fix itself doesn't depend on the mechanism — the genuine ZK JVM is only there to populate test data for clickhouse keeper-converter, so a SIGKILL after the existing 60 s SIGTERM wait is safe regardless of why the JVM was slow.

I'll update the PR description to reflect this more accurately.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Apr 28, 2026
Merged via the queue into ClickHouse:master with commit 17bab36 Apr 28, 2026
165 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 Apr 28, 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.

4 participants