Skip to content

Fix four bugs found while doing random pointless things - #112767

Merged
thevar1able merged 5 commits into
masterfrom
windows-port-bug-fixes
Aug 3, 2026
Merged

thevar1able merged 5 commits into
masterfrom
windows-port-bug-fixes

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jul 31, 2026 •

Copy link
Copy Markdown
Member

Four unrelated bugs found while cross-compiling ClickHouse for Windows. None of them are Windows-specific — the port just happened to walk into them.

1. Builds with -DENABLE_LIBFIU=OFF do not compile. The USE_LIBFIU=0 branch of FailPoint.cpp has drifted from the class it implements: it defines enablePauseFailPoint, wait and enableFromGlobalConfig, none of which FailPointInjection declares any more, and it does not define notifyPauseAndWaitForResume, which it does. That is four compile errors, and an undefined symbol at link time even without them. Verified by compiling the file with USE_LIBFIU 0 — four errors before, clean after:

src/Common/FailPoint.cpp:434:26: error: out-of-line definition of 'enablePauseFailPoint' does not match any declaration in 'DB::FailPointInjection'
src/Common/FailPoint.cpp:446:26: error: out-of-line definition of 'wait' does not match any declaration in 'DB::FailPointInjection'
src/Common/FailPoint.cpp:458:61: error: no member named 'Util' in namespace 'Poco'
src/Common/FailPoint.cpp:462:11: error: no member named 'Util' in namespace 'Poco'

The stubs only reachable through SYSTEM ENABLE|WAIT|NOTIFY FAILPOINT now throw SUPPORT_IS_DISABLED instead of silently pretending to succeed, which would leave the caller waiting for a fail point that can never fire. The hooks called from regular code paths (pauseFailPoint, notifyPauseAndWaitForResume, and disableFailPoint, which runs unconditionally during quorum cleanup in StorageReplicatedMergeTree) remain no-ops; SYSTEM DISABLE FAILPOINT still throws through InterpreterSystemQuery, which rejects all failpoint commands when built without libfiu.

2. ReadBufferFromPocoSocketBase::setReceiveTimeout sets a timeout a million times too long. It takes a count of microseconds and passes it to Poco::Timespan(long seconds, long microseconds), so the value lands in the seconds slot. It has no callers, which is why nobody noticed.

3. Two more latent LLP64 bugs. KeeperNodeStats packs three flags into the top bits of a uint64_t with 1ul << 63, 1ul << 62 and 1ul << 61, and checks the mask against ~(~0ul >> NUM_FLAGS). unsigned long is 32 bits on any LLP64 target, where all four of those are undefined behaviour and the constants come out wrong. Same for BinaryRow's 0x80L << 56 and 0x7FL << 56, which build Int64 constants. This is the same class as the two fixed in #112185 — harmless on the platforms we ship, which is exactly why they survive.

4. ConfigProcessor.cpp includes <sys/utsname.h> without using anything from it.

No tests. The failpoint fix is a build configuration CI does not exercise; the timeout has no callers to observe it through; and the shift constants have the right values on every platform we build for, so a test would pass equally before and after.

Related: #112185

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed ReadBufferFromPocoSocketBase::setReceiveTimeout applying its argument as seconds rather than microseconds, and fixed builds configured with -DENABLE_LIBFIU=OFF, which did not compile. In builds without libfiu, SYSTEM ENABLE FAILPOINT and related commands now throw an exception instead of silently doing nothing.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

🤖 Generated with Claude Code

None of these are Windows-specific; they are things the port happened to walk into.

`FailPoint.cpp`'s `USE_LIBFIU=0` branch had drifted from the class it implements. It
defined `enablePauseFailPoint`, `wait` and `enableFromGlobalConfig`, none of which
`FailPointInjection` declares any more, and did not define
`notifyPauseAndWaitForResume`, which it does. So a build configured with
`-DENABLE_LIBFIU=OFF` failed to compile the file at all - four errors - and would
have failed to link even without them. Verified by compiling the file with
`USE_LIBFIU 0`: four errors before, clean after.

`ReadBufferFromPocoSocketBase::setReceiveTimeout` took a count of microseconds and
passed it to `Poco::Timespan(long seconds, long microseconds)`, so it set a timeout a
million times longer than asked for. It has no callers, which is why nobody noticed.

`KeeperNodeStats` packs three flags into the top bits of a `uint64_t` with
`1ul << 63`, `1ul << 62` and `1ul << 61`, and checks the mask against
`~(~0ul >> NUM_FLAGS)`. `unsigned long` is 32 bits on any LLP64 target, where all four
of those are undefined behaviour and the constants come out wrong. Likewise
`BinaryRow`'s `0x80L << 56` and `0x7FL << 56` for `Int64` constants. Same class as
the two fixed in #112185; harmless on
the platforms we ship, which is exactly why they survive.

`ConfigProcessor.cpp` included `<sys/utsname.h>` without using anything from it.

No tests: the failpoint fix is a build configuration CI does not exercise, the timeout
has no callers to observe it through, and the shift constants have the right values on
every platform we build for - they are only wrong where `long` is 32 bits.

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

clickhouse-gh Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1fd68b1]

Summary: ✅


AI Review

Summary

This PR fixes a handful of portability and configuration bugs found while cross-compiling for Windows, including the USE_LIBFIU=0 stubs, a timeout-unit mixup in ReadBufferFromPocoSocketBase, and a couple of LLP64-sensitive bit masks. The FailPoint fix from the earlier review thread is now correct, but the Keeper LLP64 fix is still incomplete: one sibling mask reconstruction in Keeper node serialization still uses a 32-bit unsigned long shift, so the Windows/LLP64 bug the PR claims to remove is still present there.

Findings
❌ Blockers
  • [src/Coordination/KeeperCommon.h:127, src/Coordination/Storage/Node.cpp:319] The KeeperNodeStats LLP64 portability fix does not cover the serializer path. KeeperCommon.h now defines the top-bit flags with 1ull, but Node.cpp still uses 0xfful << (64 - 8) in the static_assert that validates those flags live in the top byte. On LLP64 that is the same 32-bit unsigned long shift the PR description calls out, so Keeper node serialization still relies on an invalid/wrong mask construction and the Windows-port fix remains incomplete.
    Suggested fix: switch the Node.cpp mask to a 64-bit expression as well (for example 0xffull << 56 or uint64_t{0xff} << 56), or better yet derive it directly from the already-fixed KeeperNodeStats constants so the invariant only lives in one place.
Final Verdict

Changes requested.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.40% -0.10%
Functions 91.90% 91.90% +0.00%
Branches 78.70% 78.60% -0.10%

Changed lines: Changed C/C++ lines covered: 0/1 (0.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 31, 2026
@alexey-milovidov alexey-milovidov changed the title Fix four bugs found while porting to Windows Fix four bugs found while doing random pointless things Jul 31, 2026
@thevar1able thevar1able self-assigned this Jul 31, 2026
The style check flagged `ErrorCodes::SUPPORT_IS_DISABLED` as defined but
not used after the removal of the stale `enableFromGlobalConfig` stub.
Rather than dropping the error code, use it: the stubs reachable through
`SYSTEM ENABLE|DISABLE|WAIT|NOTIFY FAILPOINT` now throw `SUPPORT_IS_DISABLED`
instead of silently pretending to succeed, which would leave the caller
waiting for a fail point that can never fire. The hooks called from regular
code paths (`pauseFailPoint`, `notifyPauseAndWaitForResume`) remain no-ops.

Verified that the file compiles both with `USE_LIBFIU=1` and `USE_LIBFIU=0`.

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov alexey-milovidov added pr-improvement Pull request with some product improvements and removed pr-bugfix Pull request with bugfix, not backported by default labels Jul 31, 2026
@EmeraldShift

Copy link
Copy Markdown
Contributor

Ooh, I've definitely run into the LIBFIU thing before, thank you for fixing it!

Comment thread src/Common/FailPoint.cpp Resolved
`disableFailPoint` is called unconditionally on quorum cleanup paths in
`StorageReplicatedMergeTree` and `ReplicatedMergeTreeRestartingThread`,
so throwing from the `USE_LIBFIU=0` stub would break replicated-table
recovery in such builds. The SQL entrypoints in `InterpreterSystemQuery`
already throw `SUPPORT_IS_DISABLED` when built without libfiu, so no
behavior is lost for `SYSTEM DISABLE FAILPOINT`.

Addresses the AI review finding.

Co-Authored-By: Claude Fable 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.50% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.70% 78.70% +0.00%

Changed lines: Changed C/C++ lines covered: 0/1 (0.00%) · Uncovered code

Full report · Diff report

static constexpr uint64_t CONTAINER = 1ull << 61;
static constexpr uint64_t FLAGS_MASK = EPHEMERAL | TTL | CONTAINER;
static_assert(FLAGS_MASK == ~(~0ul >> NUM_FLAGS));
static_assert(FLAGS_MASK == ~(~0ull >> NUM_FLAGS));

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.

This KeeperNodeStats mask fix stops at the struct definition. src/Coordination/Storage/Node.cpp:319 still does 0xfful << (64 - 8) in the serializer's static_assert, so on LLP64 the same 32-bit unsigned long shift remains and this portability fix is still incomplete for Keeper node serialization. Please switch that site to a 64-bit mask as well (for example 0xffull << 56 or uint64_t{0xff} << 56) in the same change.

@clickhouse-gh

clickhouse-gh Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 1fd68b134 with master 8c925c5bb (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

⚠️ Significant changes: object file sizes, slowest function optimization changes (thinlto), symbol sizes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 685.32 MiB 682.33 MiB -3.00 MiB (-0.44%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Object file sizes ⚠️

4 object files changed (-40.18 MiB total), 0 added, 685 removed.

Object file Master PR Δ
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/ext/transport/chttp2/transport/cht… 960.56 KiB removed -960.56 KiB (-100.00%)
src/Common/ZooKeeper/CMakeFiles/clickhouse_common_zookeeper_no_log.dir/ZooKeeperImpl.cpp.o 804.97 KiB removed -804.97 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/server/server.cc.o 612.22 KiB removed -612.22 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/load_balancing/rls/rls.cc.o 611.36 KiB removed -611.36 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/client_channel/client_channel_filt… 548.04 KiB removed -548.04 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/client_channel/client_channel.cc.o 525.46 KiB removed -525.46 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/client_channel/retry_interceptor.c… 518.85 KiB removed -518.85 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/lib/channel/promise_based_filter.c… 482.91 KiB removed -482.91 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/load_balancing/grpclb/grpclb.cc.o 434.97 KiB removed -434.97 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/call/client_call.cc.o 433.89 KiB removed -433.89 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/call/server_call.cc.o 391.29 KiB removed -391.29 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc++_unsecure.dir/__/grpc/src/cpp/server/server_cc.cc.o 384.88 KiB removed -384.88 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/client_channel/retry_filter_legacy… 369.55 KiB removed -369.55 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/ext/transport/chttp2/transport/wri… 349.81 KiB removed -349.81 KiB (-100.00%)
contrib/google-cloud-cpp-cmake/CMakeFiles/google_cloud_cpp_grpc_utils.dir/__/google-cloud-cpp/googl… 346.93 KiB removed -346.93 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/ext/transport/inproc/legacy_inproc… 345.35 KiB removed -345.35 KiB (-100.00%)
contrib/google-cloud-cpp-cmake/CMakeFiles/google_cloud_cpp_longrunning_operations_protos.dir/google… 339.33 KiB removed -339.33 KiB (-100.00%)
contrib/google-cloud-cpp-cmake/CMakeFiles/google_cloud_cpp_iam_credentials_v1_iamcredentials_protos… 334.24 KiB removed -334.24 KiB (-100.00%)
contrib/google-protobuf-cmake/CMakeFiles/_libprotobuf-lite.dir/__/google-protobuf/src/google/protob… 316.58 KiB removed -316.58 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/call/call_spine.cc.o 312.88 KiB removed -312.88 KiB (-100.00%)
Slowest function optimization changes (ThinLTO) ⚠️

Median per-function time ratio to the master baseline is ×1.12 (different machine and build flags); deltas below are relative to that ratio.

Binary Function Master PR Δ vs median
programs/clickhouse-keeper DB::SettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.11069338206770680048] new 17.9 s +17.9 s
programs/clickhouse DB::SettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.12487241783113815285] 8.7 s gone -9.7 s (-100%)
programs/clickhouse-keeper DB::SettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.12487241783113815285] 8.2 s gone -9.2 s (-100%)
programs/clickhouse-keeper DB::registerFunctionConversion(DB::FunctionFactory&) 6.7 s 13.9 s +6.4 s (+85%)
programs/clickhouse DB::SettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.11069338206770680048] new 6.1 s +6.1 s
programs/clickhouse-keeper _GLOBAL__sub_I_TargetLibraryInfo.cpp 5.8 s 11.4 s +4.9 s (+76%)
programs/clickhouse DB::Parquet::writeColumnChunkBody(DB::Parquet::ColumnChunkWriteState&, DB::Parquet::WriteOptions co… 5.4 s 3.2 s -2.9 s (-48%)
programs/clickhouse-keeper DB::ServerSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.54623650351436… new 2.5 s +2.5 s
programs/clickhouse DB::getSettingsChangesHistory()::$_0::operator()() const 4.5 s 2.6 s -2.5 s (-49%)
programs/clickhouse-keeper DB::MergeTreeSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.56540966842… new 2.3 s +2.3 s
programs/clickhouse DB::ServerSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.17566710545920… 2.0 s gone -2.3 s (-100%)
programs/clickhouse DB::Aggregator::writeToTemporaryFile(DB::AggregatedDataVariants&, unsigned long) const 3.6 s 1.8 s -2.3 s (-56%)
programs/clickhouse DB::attachSystemTablesServer(std::__1::shared_ptr<DB::Context const>, DB::IDatabase&, bool, bool) 4.6 s 3.0 s -2.2 s (-43%)
programs/clickhouse-keeper DB::registerFunctionVectorFunctions(DB::FunctionFactory&) 2.2 s 4.6 s +2.1 s (+88%)
programs/clickhouse-keeper _GLOBAL__sub_I_sqid.cpp 1.7 s 4.1 s +2.1 s (+109%)
programs/clickhouse DB::DatabaseDataLakeSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.9031… 1.8 s gone -2.1 s (-100%)
programs/clickhouse-keeper _ZN2DB18FunctionArrayIndexINS_16CountEqualActionENS_14NameCountEqualEE15executeIntegralIJDutjmDB8_s… 2.0 s 4.3 s +2.1 s (+92%)
programs/clickhouse DB::MergeTreeSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.16712493492… 1.8 s gone -2.0 s (-100%)
Compile time of recompiled translation units

78 translation units recompiled, 542 s compile time in total, 69 of them have a recent master baseline.

Translation units without a recent master baseline:

  • programs/keeper/Keeper.cpp (clickhouse-keeper): 6.2 s
Symbol sizes ⚠️
Binary Symbol Master PR Δ
programs/clickhouse DB::SettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.11069338206770680048] new 439.45 KiB +439.45 KiB
programs/clickhouse-keeper DB::SettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.11069338206770680048] new 439.45 KiB +439.45 KiB
programs/clickhouse DB::SettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.12487241783113815285] 439.45 KiB removed -439.45 KiB (-100.00%)
programs/clickhouse-keeper DB::SettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.12487241783113815285] 439.45 KiB removed -439.45 KiB (-100.00%)
programs/clickhouse DB::ServerSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.54623650351436… new 114.16 KiB +114.16 KiB
programs/clickhouse-keeper DB::ServerSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.17566710545920… 114.16 KiB removed -114.16 KiB (-100.00%)
programs/clickhouse-keeper DB::ServerSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.54623650351436… new 114.16 KiB +114.16 KiB
programs/clickhouse DB::ServerSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.17566710545920… 114.16 KiB removed -114.16 KiB (-100.00%)
programs/clickhouse-keeper DB::MergeTreeSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.56540966842… new 102.51 KiB +102.51 KiB
programs/clickhouse DB::MergeTreeSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.56540966842… new 102.51 KiB +102.51 KiB
programs/clickhouse-keeper DB::MergeTreeSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.16712493492… 102.51 KiB removed -102.51 KiB (-100.00%)
programs/clickhouse DB::MergeTreeSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.16712493492… 102.51 KiB removed -102.51 KiB (-100.00%)
programs/clickhouse DB::DatabaseDataLakeSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.1111… new 97.41 KiB +97.41 KiB
programs/clickhouse DB::DatabaseDataLakeSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.9031… 97.41 KiB removed -97.41 KiB (-100.00%)
programs/clickhouse DB::ObjectStorageQueueSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.14… new 92.15 KiB +92.15 KiB
programs/clickhouse DB::ObjectStorageQueueSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.10… 92.15 KiB removed -92.15 KiB (-100.00%)
programs/clickhouse DB::KafkaSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.872715978862839… new 89.47 KiB +89.47 KiB
programs/clickhouse DB::KafkaSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.176316896530569… 89.47 KiB removed -89.47 KiB (-100.00%)
programs/clickhouse DB::DataLakeStorageSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.41967… 88.38 KiB removed -88.38 KiB (-100.00%)
programs/clickhouse DB::DataLakeStorageSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.13841… new 88.38 KiB +88.38 KiB

Job report

@thevar1able
thevar1able added this pull request to the merge queue Aug 3, 2026
Merged via the queue into master with commit 87e20dd Aug 3, 2026
180 checks passed
@thevar1able
thevar1able deleted the windows-port-bug-fixes branch August 3, 2026 13:38
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements 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