Repository navigation
Fix a data race on the exit code of the embedded client in the SSH server - #127990
PedroTadim merged 5 commits into
Conversation
…rver `ClientEmbeddedRunner::exit_code` was a plain `int`, written by the embedded client thread when `client.run()` returns and read by the SSH handler for `sendExitStatus` as soon as its loop ends. When the loop ends because the channel was closed or the server is shutting down while the client still runs, nothing orders the read before the write, which ThreadSanitizer reported in `Stress test (amd_tsan)` (STID 3766-25fc) once ClickHouse#125517 started running stress queries over SSH and killing clients. Make it a `std::atomic<int>`, like the neighbouring `waiting_for_query_input` and `prompts_count`. The values are unchanged: a reader that runs before the client finishes still gets the default 1. The new gtest reads the exit code right after starting a client that prints its version, with no synchronization in between, and then checks that the final code is 0 once the client has finished (which proves the write happened). Under TSan it aborts with the CI report pair without the fix and passes with it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (0 findings). Nothing to adjudicate. Session id: cron:clickhouse-review-slot-9:20261027-174300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261027-164000 |
|
cc @yakov-olkhovskiy @CheSema, could you review this and add the |
|
Workflow [PR], commit [5a26579] Summary: ✅
AI ReviewSummaryMakes Final VerdictStatus: ✅ Approve |
It is the first unit test that links the embedded client, so `unit_tests_dbms` grows by 7.01 MiB in `Build (amd_msan)`, more than the 5 MiB the `Relocation headroom` check allows. Any unit test of the runner pulls the same code in, because `ClientEmbeddedRunner.cpp` constructs the client. The fix itself does not change the size of any binary. The TSan validation it gave stays in the PR description: without the fix it aborted 5/5 with the CI report pair, with the fix it passed 5/5 plus `--gtest_repeat=100`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 1560828Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261028-020005 |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units9 translation units recompiled, 26 s compile time in total, 9 of them have a recent master baseline. |
|
🕵 Merged the latest |
|
#125293 is green and mergeable but has no approving review yet, and I can't approve, merge or label PRs here, so it needs a maintainer to approve it and merge it with |
|
🕵 Merged the latest |
|
I merged the latest The red It needs an approving review to merge (the request to @ CheSema from 2026-10-08 is still pending); I can't approve or merge it myself. |
Related: #125517
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Description
Stress test (amd_tsan)reportedThreadSanitizer: data race (STID: 3766-25fc): https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125726&sha=19f6e90988c4dd33438e600f107791363c5f8d9f&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29The embedded client thread writes
ClientEmbeddedRunner::exit_code(a plainint) whenclient.run()returns. The SSH handler reads it forsendExitStatusas soon as its loop ends. When the loop ends because the channel closed or the server is shutting down while the client is still running, nothing orders the read before the write. The stress test reaches this since #125517 runs queries over SSH and kills clients mid-query.The fix makes
exit_codeastd::atomic<int>, like its neighbourswaiting_for_query_inputandprompts_count. The values are unchanged: a reader that runs before the client finishes still gets the default1.No released version shows a user-visible effect (the status sent is the default
1or the client's code either way), hence not a bug fix.Validation: a local gtest that reads the exit code right after starting a client aborts 5/5 on a TSan build without the fix, with the same report pair, and passes 5/5 plus
--gtest_repeat=100with it. It is not part of this PR: it is the first unit test that links the embedded client, which growsunit_tests_dbmsby 7 MiB, more than theRelocation headroomcheck ofBuild (amd_msan)allows.Workflow [PR]
Sync PR [sync-upstream/pr/127990]
Version info
26.11.1.966-master(included in26.11and later)