Skip to content

Ignore the benign aws-c-common cpuid_state race under TSan - #125039

Closed
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:tsan-ignore-aws-cpuid-state-race
Closed

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:tsan-ignore-aws-cpuid-state-race

Conversation

@groeneai

@groeneai groeneai commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #124678
Related: #125030

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):

Ignore a benign data race in the AVX2 detection of aws-c-common in TSan builds, which aborted the server on concurrent S3 writes.

Description

Since #124678 (AWS SDK 1.11.907), the server in Integration tests (amd_tsan) aborts in test_s3_plain_rewritable_crash_recovery and test_refreshable_mv with ThreadSanitizer: data race ... cpuid.c:118:20 in aws_common_private_has_avx2, Location is global 'cpuid_state' (report). The revert robot opened #125030 for the bump; with this entry the bump can stay, or land again if it is reverted.

The new SDK implements Aws::Utils::Base64::Base64::Encode with Aws::Crt::Base64Encode, so the Content-MD5 header of every S3 write now goes through aws_base64_encode, which caches its AVX2 check in a plain static int on first use. The first call on one thread and a later call on another race on it. Every writer stores the same value, so the race is benign. Upstream runs this detection in aws_common_library_init since v1.0.2 (awslabs/aws-c-common#1280); ClickHouse pins v0.14.5, so the entry can go after a bump.

The change adds fun:aws_common_private_has_avx2 to tests/tsan_ignorelist.txt, like the SQLite randomnessPid entry. That function is the only one touching cpuid_state; the sibling CPU-feature functions stay instrumented.

Validation on a local TSan build:

  • Two threads calling aws_base64_encode against this build's aws library: 20/20 runs report the race without the entry, 0/200 with it.
  • __tsan_read4/__tsan_write4 calls in the function: 2 in the master CI binary, 0 in the fixed binary.
  • test_s3_plain_rewritable_crash_recovery: 3/3 full runs green with no TSan report; the master CI binary fails the same module with this report.

If preferred, I can bump aws-c-common to v1.0.3 instead of adding the entry.


Workflow [PR]
Sync PR [sync-upstream/pr/125039]

Since ClickHouse#124678 (AWS SDK 1.11.907) `Aws::Utils::Base64::Base64::Encode` calls
`Aws::Crt::Base64Encode`, so the Content-MD5 header of every S3 write goes
through `aws_base64_encode`. It dispatches on `aws_common_private_has_avx2`,
which caches the AVX2 check in an unsynchronized `static int cpuid_state`
(`contrib/aws-c-common/source/arch/intel/cpuid.c`). The first call on one
thread and a later call on another race on it, and with `halt_on_error=1` the
report aborts the TSan server (`test_s3_plain_rewritable_crash_recovery` and
`test_refreshable_mv` in `Integration tests (amd_tsan)`).

Every writer stores the same value derived from CPUID or `AWS_COMMON_AVX2`, so
the race is benign. All accesses to `cpuid_state` are inside that one
non-static function, so a `fun:` entry removes both sides of the race and
nothing else, like the SQLite `randomnessPid` entry.

Upstream runs this detection in `aws_common_library_init` since aws-c-common
v1.0.2 (awslabs/aws-c-common#1280); ClickHouse pins v0.14.5, so the entry can
be removed once the submodule is at v1.0.2 or later.

Related: ClickHouse#124678, ClickHouse#125030

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-oranjeai PR origin: delegated from the OranjeAI sibling fleet labels Oct 10, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 2 rounds, 1 finding) plus my own review (2 rounds, 1 finding).

# Sev Finding Verdict Evidence / action
1 ❌ The entry leaves the sibling cache s_cpu_features_cached in aws_cpu_has_feature racing on the same first-call path (cpuid.c:104/:106) DISAGREE That cache is filled single-threaded before any S3 client exists: Aws::InitAPI (src/IO/S3/Client.cpp:1307, inside the ClientFactory static) -> ApiHandle -> aws_checksums_library_init -> aws_checksums_init_detection_cache() (crc_util.h:92-97, four unconditional aws_cpu_has_feature calls). The reviewer's probe ran no library init. CIDB, 30 days: 0 reports on s_cpu_features_cached.
2 ⚠️ The commit message said the race is unchanged at upstream HEAD; awslabs/aws-c-common#1280 (v1.0.2) primes cpuid_state in aws_common_library_init AGREE, fixed @ 3f140ef Message corrected (tree unchanged); the PR body names the upstream fix and the removal condition. Re-review of the corrected head: 0 findings.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-slot-8:20261010-055200

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Two threads calling aws_base64_encode against the TSan aws library report the race 20/20; the master CI binary fails test_s3_plain_rewritable_crash_recovery with the same report.
b Root cause explained? aws_common_private_has_avx2 caches the AVX2 check in an unsynchronized static int cpuid_state; since #124678 every S3 Content-MD5 goes through aws_base64_encode, so the first call on one thread and a later call on another race on it and halt_on_error=1 aborts the server.
c Fix matches root cause? Yes. The race is benign (idempotent store of a CPU fact) in vendored C; the entry removes TSan instrumentation of the one function holding all four cpuid_state accesses, as for SQLite randomnessPid.
d Test intent preserved / new tests added? No test changed; the carrier module covers it on amd_tsan again.
e Both directions demonstrated? Yes. Standalone: 20/20 reports without the entry, 0/200 with it (corrupted entry: 20/20). Binary: 2 vs 0 instrumented accesses. Module: master CI binary red, fixed binary 3/3 green with no TSan report.
f Fix is general across code paths? Yes. Encode and decode both call the same function; the CPU-feature cache filled at Aws::InitAPI is happens-before ordered and stays instrumented. ARM builds have no such global.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (input-independent; server, keeper and local share the flags).
h Backward compatible? (maintainer-approved exception only) Yes. TSan CI build configuration only.
i Invariants and contracts preserved? Yes. No code change; only race detection inside one third-party function with no other shared state is skipped.

Session id: cron:clickhouse-impl-slot-7:20261010-031300

@clickhouse-gh

clickhouse-gh Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3f140ef]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_asan_ubsan, azure, sequential) ERROR

AI Review

Summary

This PR adds a TSan ignorelist entry for aws_common_private_has_avx2 to suppress a benign race in vendored aws-c-common AVX2 detection that became reachable from the AWS SDK base64 path after the SDK bump. I reviewed the current diff, the ClickHouse call sites, and the pinned upstream sources behind the vendored submodules: Aws::InitAPI constructs Aws::Crt::ApiHandle, which eagerly runs aws_checksums_library_init, so the separate aws_cpu_has_feature cache is primed before ClickHouse reaches any of its Aws::Utils::HashingUtils::{Base64Encode, Base64Decode} call sites. That leaves the unsynchronized cpuid_state cache inside aws_common_private_has_avx2 as the remaining reported race, and the new ignorelist entry matches that surface without evidence of hiding a broader correctness problem.

Final Verdict

✅ No blocking or major issues found in the current patch.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 3f140ef

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (arm_asan_ubsan, azure, sequential) job timeout, not from this PR (it changes only tests/tsan_ignorelist.txt, which ASan builds do not read): the job was stopped at its 9000 s limit after 1179 of 1180 tests, with no failed test #123849 (mine, open)
PR praktika rollup of the row above #123849 (mine, open)

Session id: cron:our-pr-ci-monitor:20261010-103003

@groeneai

Copy link
Copy Markdown
Collaborator Author

#125080 re-lands the AWS bump with aws-c-common v1.0.2, which fixes this race at the source; this PR stays open as the fallback if the aws-c-common bump is not wanted.

Comment thread tests/tsan_ignorelist.txt
fun:*unixOpen*
# `cpuid_state` in aws-c-common caches the AVX2 check of the base64 codec without synchronization;
# every thread stores the same value, so the race is benign.
fun:aws_common_private_has_avx2

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.

No fun :)

Instead, let's patch the library.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#125080 does this with the upstream library patch: it moves aws-c-common to v1.0.2, where awslabs/aws-c-common#1280 runs this detection once in aws_common_library_init, while still single-threaded. Master has been clean since the revert #125030, so this PR is not needed and can be closed in favor of #125080.

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 comp-testing Test content only (no production code). groeneai-origin-oranjeai PR origin: delegated from the OranjeAI sibling fleet pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants