Skip to content

Clear LLVM_PROFILE_FILE for manual clickhouse launches in test_server_reload - #101912

Merged
azat merged 2 commits into
ClickHouse:masterfrom
groeneai:fix/llvm-profile-stderr-filter
Apr 9, 2026
Merged

azat merged 2 commits into
ClickHouse:masterfrom
groeneai:fix/llvm-profile-stderr-filter

Conversation

@groeneai

@groeneai groeneai commented Apr 7, 2026 •

Copy link
Copy Markdown
Collaborator

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 to CHANGELOG.md):

  • Not required

What this PR does

In coverage builds (amd_llvm_coverage), test_change_listen_host and test_reload_via_client launch clickhouse inside a container via docker exec. These processes inherit LLVM_PROFILE_FILE from the container environment and can select the same merge-pool slot (%4m) as the running server, causing file-lock races that produce LLVM Profile Error: Failed to write file...File exists on stderr. The test helper then treats this non-empty stderr as a query failure.

Fix: Pass -e LLVM_PROFILE_FILE= to docker exec for these manual launches, clearing the variable so the profiler is disabled for the short-lived client processes. The server's profiling is unaffected.

Root cause (identified by @alexbakharew): The manually-launched clickhouse processes inside the container inherit the LLVM_PROFILE_FILE=%4m pattern. With only 4 hash slots, the client can select the same pool_id the server already holds, causing a file conflict.

Scope: Only the two affected tests are changed — the global LLVM_PROFILE_FILE setting in cluster.py is left at %4m as intended.

CIDB data: 29 failures in 30 days, exclusively on Integration tests (amd_llvm_coverage, 5/5), affecting 27 distinct PRs and 3 master runs.

@groeneai

groeneai commented Apr 7, 2026

Copy link
Copy Markdown
Collaborator Author

Pre-PR Validation (session: cron:clickhouse-ci-task-worker:20260407-091500)

a) Deterministic repro?
Cannot reproduce locally — failure requires LLVM coverage instrumentation (amd_llvm_coverage builds). However, all 16 post-March-30 CI failures show the identical error trace: LLVM Profile Error: Failed to write file "...profraw": File exists → QueryRuntimeException with returncode 0 at helpers/client.py:269. The trigger is deterministic in coverage builds.

b) Root cause explained?
In coverage builds, clickhouse-client exits after executing a query. The LLVM profiler tries to write .profraw files but encounters file-exists conflicts with other processes. This produces LLVM Profile Warning: and LLVM Profile Error: lines on stderr. The integration test helper's get_answer() checks self.remove_trash_from_stderr(stderr) — which does NOT filter LLVM messages — and raises QueryRuntimeException because cleaned stderr is non-empty, even though returncode is 0.

c) Fix matches root cause?
Yes — adds LLVM profile patterns to the existing remove_trash_from_stderr filter, directly preventing those lines from triggering the exception. Same pattern as existing completion_queue and Kick failed filters.

d) Test intent preserved?
Yes — no changes to any test file. Only the infrastructure helper's noise filter is extended. test_change_listen_host continues to validate config reload behavior exactly as before.

e) Both directions demonstrated?

  • WITHOUT fix: 16/16 post-March-30 CI failures show LLVM profile stderr → exception (verified via CIDB test_context_raw)
  • WITH fix: LLVM profile lines filtered → empty stderr → no exception (verified via unit test simulation of the filter function with exact CI error patterns — all 7 test cases pass)

f) Fix is general?
Yes — fix is in the shared helpers/client.py, protecting ALL integration tests from LLVM profiler stderr noise. Checked for other stderr-handling code in tests/integration/helpers/ — remove_trash_from_stderr is the only filter point.

@groeneai

groeneai commented Apr 7, 2026

Copy link
Copy Markdown
Collaborator Author

cc @azat — could you review this? It extends remove_trash_from_stderr in the integration test client helper to filter LLVM profiler warnings/errors that cause test_change_listen_host to fail on coverage builds. Your previous fix (PR #101213) resolved the config reload timing issue, but LLVM profile file contention on stderr is a separate failure mode that continued (16 hits post-merge).

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Apr 7, 2026
@clickhouse-gh

clickhouse-gh Bot commented Apr 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [830a8fc]

Summary: ✅


AI Review

Summary

This PR fixes a flaky failure in amd_llvm_coverage integration tests by clearing LLVM_PROFILE_FILE for manually launched clickhouse client processes inside the container in two tests. This is a targeted, low-risk CI reliability change in test code only, and the implementation matches the stated root cause.

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 ✅
Final Verdict
  • Status: ✅ Approve

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

@azat azat 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.

I doubt that this is the correct fix, why do you think just ignoring errors is OK?

@azat

azat commented Apr 7, 2026

Copy link
Copy Markdown
Member

On exit, the LLVM profiler tries to write .profraw files — file conflicts produce stderr warnings

@groeneai Why?

Change LLVM_PROFILE_FILE from %4m (merge-mode pool of 4) to %p (per-PID)
inside Docker containers. Server and docker-exec'd client processes share
the same container environment, causing file-lock races on the 4 merge-pool
entries when multiple processes exit concurrently. Per-PID files eliminate
the contention entirely.

The CI merge step (merge_profraw_files / llvm-profdata merge -sparse)
already handles arbitrary numbers of .profraw files.
@groeneai
groeneai force-pushed the fix/llvm-profile-stderr-filter branch from 27304ae to 905bda0 Compare April 7, 2026 12:22
@groeneai groeneai changed the title Filter LLVM profile warnings from integration test client stderr Fix LLVM profile file conflicts in integration test containers Apr 7, 2026
@groeneai

groeneai commented Apr 7, 2026

Copy link
Copy Markdown
Collaborator Author

@azat You're right — filtering is wrong here. I've reworked the PR to fix the root cause.

Why the conflicts happen: helpers/cluster.py sets LLVM_PROFILE_FILE=/debug/it-%4m.profraw for all processes inside the Docker container. The %4m pattern uses LLVM's merge mode with a pool of 4 hash-based file entries. Both the clickhouse-server process and any docker exec'd clickhouse-client processes (this test uses docker exec — see test_change_listen_host line 313) share this same container environment. When multiple processes exit concurrently and try to acquire advisory file locks on the same pool slots for profile data merging, one gets "File exists".

New fix: Changed %4m → %p in cluster.py so each process writes to a per-PID file (/debug/it-<PID>.profraw). No shared pool = no contention. The CI merge step (merge_profraw_files() using llvm-profdata merge -sparse) already discovers all .profraw files via Path(".").rglob("*.profraw"), so this is seamless.

Dropped the stderr filter entirely — the profiler errors should simply not happen anymore.

@alexbakharew

Copy link
Copy Markdown
Contributor

@azat the issue is hidden in tests/integration/test_server_reload/test.py. This error happens only for this test. I will check something and provide the fix shortly

@groeneai

groeneai commented Apr 7, 2026

Copy link
Copy Markdown
Collaborator Author

@alexbakharew Makes sense — CIDB confirms all 29 failures in the last 30 days are exclusively this test. Happy to defer if you have a test-specific fix. I can close this PR once yours is up.

@alexbakharew

alexbakharew commented Apr 7, 2026 •

Copy link
Copy Markdown
Contributor

@groeneai the problem is that in test cases test_reload_via_client and test_change_listen_host clickhouse is launched inside a container manually. These launches inherit the LLVM_PROFILE_FILE value. And in may happen that this launch may select the same pool_id as the server has already acquired and writes into it. This issue is very sporadic. The solution is to clear the LLVM_PROFILE_FILE value for current container launch before actually launching it. The main LLVM_PROFILE_FILE should not be affected. Please implement and test the fix

@alexbakharew

Copy link
Copy Markdown
Contributor

@azat You're right — filtering is wrong here. I've reworked the PR to fix the root cause.

Why the conflicts happen: helpers/cluster.py sets LLVM_PROFILE_FILE=/debug/it-%4m.profraw for all processes inside the Docker container. The %4m pattern uses LLVM's merge mode with a pool of 4 hash-based file entries. Both the clickhouse-server process and any docker exec'd clickhouse-client processes (this test uses docker exec — see test_change_listen_host line 313) share this same container environment. When multiple processes exit concurrently and try to acquire advisory file locks on the same pool slots for profile data merging, one gets "File exists".

New fix: Changed %4m → %p in cluster.py so each process writes to a per-PID file (/debug/it-<PID>.profraw). No shared pool = no contention. The CI merge step (merge_profraw_files() using llvm-profdata merge -sparse) already discovers all .profraw files via Path(".").rglob("*.profraw"), so this is seamless.

Dropped the stderr filter entirely — the profiler errors should simply not happen anymore.

@groeneai fyi:
This change %4m → %p is inappropriate since we launch huge amount of tests. Each call will produce new .profraw file. In this scenario, we will run out of disk space constantly. LLVM Coverage can't be collected at all using this value

…_reload

In coverage builds, test_change_listen_host and test_reload_via_client
launch clickhouse inside a container via `docker exec`. These processes
inherit LLVM_PROFILE_FILE from the container environment and can select
the same merge-pool slot (%4m) as the running server, causing file-lock
races that produce "LLVM Profile Error: Failed to write file" on stderr.
The test helper then treats this non-empty stderr as a query failure.

Fix: pass `-e LLVM_PROFILE_FILE=` to `docker exec` for these manual
launches, clearing the variable so the profiler is disabled for the
short-lived client processes. The server's profiling is unaffected.

Revert the previous %4m→%p change in cluster.py since the issue is
specific to these two tests, not a global container problem.
@groeneai groeneai changed the title Fix LLVM profile file conflicts in integration test containers Clear LLVM_PROFILE_FILE for manual clickhouse launches in test_server_reload Apr 7, 2026
@groeneai

groeneai commented Apr 7, 2026

Copy link
Copy Markdown
Collaborator Author

@alexbakharew Done — implemented your fix direction.

Changes in 830a8fc:

  1. Reverted the %4m→%p change in helpers/cluster.py — the global profile file pattern stays at %4m as intended
  2. Added -e LLVM_PROFILE_FILE= to docker exec in both test_change_listen_host and test_reload_via_client

This clears the profiler env var for the manually-launched clickhouse-client processes inside the container, preventing them from racing with the server over the same merge-pool slots. The server's profiling remains unaffected.

The fix is minimal — only the two test functions that use docker exec to launch clickhouse are touched.

"exec",
"-i",
"-e",
"LLVM_PROFILE_FILE=",

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.

@alexbakharew is this OK? Then, where the profile file will be written? (if any) How we will collect coverage from it? (not a big deal for this specific test, but just wondering)

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 is the only one place where we execute the CH in docker manually. With our use case we can't afford switching from %4m mode to %p - the last option solves the issue.

For these 2 tests we just disable coverage collection for launching CH binary. It is disabled only in-place, general coverage collection is not affected.

So we just ignore the coverage for these 2 calls. I do not expect coverage degradation, but want to prove it once the CI is finished

@alexbakharew

Copy link
Copy Markdown
Contributor

@azat can we merge it?

@azat
azat added this pull request to the merge queue Apr 9, 2026
Merged via the queue into ClickHouse:master with commit 3e6118c Apr 9, 2026
317 of 320 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 9, 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.

5 participants