Skip to content

fix(Keeper): Add fallback to IPv4 for Raft listener if IPv6 fails - #85901

Merged
pamarcos merged 2 commits into
ClickHouse:masterfrom
jskong1124:fix-keeper-ipv6-fallback
Aug 26, 2025
Merged

pamarcos merged 2 commits into
ClickHouse:masterfrom
jskong1124:fix-keeper-ipv6-fallback

Conversation

@jskong1124

@jskong1124 jskong1124 commented Aug 19, 2025 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

ClickHouse Keeper no longer fails to start on systems where IPv6 is disabled at the kernel level (e.g., RHEL with ipv6.disable=1). It now attempts to fall back to an IPv4 listener if the initial IPv6 listener fails.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Hi there! This is a follow-up to PR #85400.

The last one was closed after I struggled with the integration test and accidentally deleted the branch. I've since set up the full local test environment and added a proper test to validate this fix.

Problem:

Keeper fails to start on hosts with kernel-level IPv6 disabled (e.g., ipv6.disable=1 on RHEL 8). It throws a generic Address family not supported by protocol error in the log.
While the documentation suggests setting <keeper_server.enable_ipv6>false</keeper_server.enable_ipv6>, the actual error message doesn't hint at this, making the issue difficult to debug.

<Error> RaftInstance: got exception: open: Address family not supported by protocol [system:97] on port 9444
<Error> DB::Exception: Cannot create interserver listener on port 9444. (RAFT_ERROR)

Fix:

Same C++ change as before. It adds a simple fallback: if the default listener (with IPv6) fails, it logs a warning and automatically retries with an IPv4-only listener. This lets Keeper start on IPv4-only systems without requiring users to debug the issue and manually change the configuration.

Test (test_keeper_ipv4_fallback/test.py):

  1. Using sysctl to disable IPv6 in the test container.
  2. Starting a standard 3-node Keeper cluster.
  3. Asserting the cluster is healthy with a ruok check to zoo1.
  4. Restoring the IPv6 setting on teardown.

Thanks!

(P.S. English isn't my first language, so my apologies for any awkward phrasing.)

@pamarcos pamarcos added the can be tested Allows running workflows for external contributors label Aug 20, 2025
@pamarcos
pamarcos self-requested a review August 20, 2025 10:31
@pamarcos pamarcos self-assigned this Aug 20, 2025
@clickhouse-gh

clickhouse-gh Bot commented Aug 20, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [bf70532]

Summary: ❌

job_name test_name status info comment
Bugfix validation (integration tests) failure

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 20, 2025

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

First of all, thanks for your contribution and for pursuing the work in a following PR. Much appreciated 🫂

The idea and the C++ code looks fine.
I have comments regarding the test, though:

  1. The test finishes successfully with current build from master without your changes, so it doesn't seem to be a good check for your changes
  2. We're skipping the test in case we're not root, but at that point we've already tried to run commands that require root privileges. Shouldn't we skip all the tests of the module and even the module fixture if we don't have root access?
  3. Since you're disabling IPv6 system-wise, you may affect other tests. If you want to make sure this tests runs sequentially, you need to add it to the list in parallel_skip.yaml

Let me also ping @antonio2368 for some extra eyes, since he already reviewed the original PR

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.

In case the sysctl cannot be executed we fail on this fixture, but on the other hand we skip the test if we are not root.

Comment on lines 13 to 14

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.

If anything happens here that throws, we're never enabling IPv6 again. We should make a more resilient solution to ensure if we disable IPv6, it's always enabled back after the tests, no matter what.

@jskong1124
jskong1124 force-pushed the fix-keeper-ipv6-fallback branch from 103fa0d to bf70532 Compare August 25, 2025 18:24
@jskong1124

jskong1124 commented Aug 25, 2025 •

Copy link
Copy Markdown
Contributor Author

Hi @pamarcos
Apologies for the delay. Your feedback was spot on—thank you. I've investigated why the initial test passed on master and found the issue is more nuanced than expected.

There's a key difference in how Keeper behaves depending on how IPv6 is disabled:

"Soft" Disable (via sysctl):
The original code handles this. It logs a non-fatal warning but starts successfully on IPv4. This is what my test was simulating, hence the false positive.

"Hard" Disable (via ipv6.disable=1 kernel param):
This is the scenario my patch fixes. The original code crashes with a fatal Address family not supported error because the kernel module isn't loaded.

Unfortunately, replicating the "hard" disable in CI seems impossible. I've confirmed my patch works in a manual test with the kernel param, but I can't create an automated test that fails on master and passes with my fix.

If you have any ideas for how to test this scenario in CI, I'd be grateful for your advice.

Thanks again for your help and patience!

(P.S. English isn't my first language, so my apologies for any awkward phrasing.)

@pamarcos

Copy link
Copy Markdown
Member

Thanks for the taking care of this! I've fixed a conflict in the private fork so we'll have to wait for the CH Inc sync to finish before merging, but since on the OSS version only the bugfix validation failed, I'm confident it'll work. I'll override the result of this CI job to be able to merge, because the bugfix validation checks precisely that the new test works with the new code but fails with the prior one.

Unfortunately, replicating the "hard" disable in CI seems impossible

Yeah, even if it's possible disabling IPv6 for a new docker instance that runs only that test, it seems a little overkill.

No need to apologize for the delay or for not not being a native English-speaker! As you can guess, most of us aren't but we still manage to communicate succesfully :)

I've reworded slightly the CHANGELOG description from "no longer crashes on startup" to "no longer fails to start" because it was not a real crash, was it?

@jskong1124

Copy link
Copy Markdown
Contributor Author

Hi @pamarcos
Thank you for the review and for handling the conflicts! I'm glad the fix is acceptable.

And yes, you are absolutely right about the changelog entry. "fails to start" is much more accurate since it wasn't a crash in the strict sense.

Thanks for catching that and making the correction.
I really appreciate your help and guidance through this whole process. 😊

@pamarcos
pamarcos added this pull request to the merge queue Aug 26, 2025
Merged via the queue into ClickHouse:master with commit 51e603b Aug 26, 2025
@pamarcos

Copy link
Copy Markdown
Member

Merged, thanks a lot for your contribution 🫂

@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 26, 2025
Algunenano pushed a commit to Algunenano/ClickHouse that referenced this pull request Nov 19, 2026
…ntegration job

The module runs `sysctl -w net.ipv6.conf.all.disable_ipv6=1`, starts its
cluster, and writes `=0` in `finally`. pytest runs as root in the
integration job container, so this flips IPv6 in the job container's
network namespace, where the nested dockerd's bridges and every pytest
process live.

Disabling IPv6 flushes every IPv6 address in that namespace. The restore
brings back only what the kernel generates (`::1`, link-local
addresses), not dockerd's static `fd00::1/8` on `docker0`
(`fixed-cidr-v6: fd00::/8`), and it also enables IPv6 on the container's
uplink, which Docker had disabled. For the rest of the job the namespace
has no global IPv6 source address except the gateways of the compose
bridges themselves.

The gateway of a new compose network (`2001:3984:3989::1` for
test_grpc_protocol) is added with duplicate address detection, so it is
tentative for 1-2 s. A TCP connect to the container's IPv6 address
issued in that window has to pick another source: before the toggle
that is `fd00::1` and the connection completes as soon as DAD ends;
after the toggle it is a link-local address of another interface (or
`::1`), the container's reply to it cannot be delivered over the bridge,
and the SYN is retransmitted from the same source until the 10 s
`channel_ready_future` budget of `test_ipv6_select_one` runs out.

Only the targeted check is affected: it moves test_grpc_protocol (a
fixed-address module) to the sequential phase, after every parallel
module, so the toggle always precedes it, and the release arm_binary
server is ready within the DAD window. The regular shards run
test_grpc_protocol before the keeper module. CIDB, 30 days, rows of
test_ipv6_select_one:

  arm targeted, keeper module in the same job       3 FAIL / 14 OK
  arm targeted, keeper module not in the job        0 FAIL / 553 OK
  amd sanitizer targeted, keeper module in the job  0 FAIL / 50 OK
  regular arm shards (grpc runs before keeper)      0 FAIL / 7500 OK

Reproduced in private network namespaces modelled on the job container:
a 10 s connect started while the gateway is tentative completes in ~2 s
with source `fd00::1` before the toggle (3/3) and times out with a
`fe80::` source after it (3/3).

The module does not test what it claims. `[::]` still binds with
`disable_ipv6=1`, so NuRaft's IPv6 acceptor never fails and the IPv4
fallback in `KeeperServer::launchRaftServer` is never reached; that
needs `socket(AF_INET6)` itself to fail, as with the `ipv6.disable=1`
boot parameter, which a CI container cannot emulate (the author of
ClickHouse#85901 said so, and its Bugfix validation failed on master). The Keeper
containers get fresh network namespaces that do not inherit the toggle,
and `keeper_ipv6_enabled.xml` is a user config of `node1`, which runs no
Keeper. The module was kept sequential until 511c5a1 made it
parallel.

Drop its line from RAW_TEST_DURATIONS and from the durations sample, as
in 95af852.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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-bugfix Pull request with bugfix, not backported by default 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.

3 participants