Skip to content

Fix stop_zookeeper not waiting for ZooKeeper JVM in test_keeper_zookeeper_converter - #102492

Merged
alexey-milovidov merged 2 commits into
masterfrom
fix-keeper-zookeeper-converter-stop
Apr 19, 2026
Merged

alexey-milovidov merged 2 commits into
masterfrom
fix-keeper-zookeeper-converter-stop

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Apr 12, 2026 •

Copy link
Copy Markdown
Member

stop_zookeeper used get_process_pid("zookeeper") to wait for the process to die, but get_process_pid uses the regex '^[^ ]*zookeeper' which only matches the first word of the command line. The ZooKeeper Java process starts with java -Dzookeeper.log.dir=..., so the first word is java, not zookeeper — the regex never matched and the function returned immediately without actually waiting for the process to exit.

Under resource-constrained environments (MSan), the JVM takes longer to shut down after zkServer.sh stop. When start_zookeeper was called later, the old process was still holding port 2181, causing the new JVM to fail with exit code 1.

Fix by using pgrep -f org.apache.zookeeper.server to properly detect the running ZooKeeper JVM process. Also increase start retries from 3 to 5 with 3-second delays as an additional safety net.

CI report: 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

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

…eper_zookeeper_converter

`stop_zookeeper` used `get_process_pid("zookeeper")` to wait for the
process to die, but `get_process_pid` uses the regex `'^[^ ]*zookeeper'`
which only matches the first word of the command line. The ZooKeeper Java
process starts with `java -Dzookeeper.log.dir=...`, so the first word
is `java`, not `zookeeper` — the regex never matched and the function
returned immediately without waiting.

Under resource-constrained environments (MSan), the JVM takes longer to
shut down after `zkServer.sh stop`. When `start_zookeeper` was called
later, the old process was still holding port 2181, causing the new JVM
to fail with exit code 1.

Fix by using `pgrep -f org.apache.zookeeper.server` to properly detect
the running ZooKeeper JVM process. Also increase start retries from
3 to 5 with 3-second delays as an additional safety net.

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

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Apr 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0025d52]

Summary: ✅


AI Review

Summary

This PR fixes a flaky integration test shutdown/startup sequence for ZooKeeper in test_keeper_zookeeper_converter: it replaces get_process_pid("zookeeper") (which cannot match Java-based ZooKeeper cmdlines) with pgrep -f against ZooKeeper’s JVM main class and increases startup retries. The change is scoped, correct for the stated failure mode, and does not introduce new correctness/safety/performance risks.

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 12, 2026
The previous fix used `pgrep -f org.apache.zookeeper.server` inside a
`bash -c ...` wrapper to detect the ZooKeeper JVM. But `pgrep -f` matches
the full command line of every process, and the wrapping bash process
itself has `org.apache.zookeeper.server` in its own argv — so pgrep
always matched the shell running it, never returning empty, and the wait
loop timed out after 60 seconds.

Use the standard bracket-expression trick: the regex
`[o]rg\.apache\.zookeeper\.server` matches the literal string
`org.apache.zookeeper.server` but does not match its own pattern
`[o]rg\.apache\.zookeeper\.server` that appears in the shell's argv.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=102492&sha=e220a72e8388401e2ebe63cd04a70c18c6c5f9d6&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20flaky%29

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

@alexey-milovidov alexey-milovidov left a comment

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.

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Apr 19, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Apr 19, 2026
Merged via the queue into master with commit c5ecc9a Apr 19, 2026
161 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-keeper-zookeeper-converter-stop branch April 19, 2026 12:54
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 19, 2026
pull Bot pushed a commit to Mu-L/ClickHouse that referenced this pull request Apr 28, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants