Skip to content

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

Closed
jskong1124 wants to merge 1 commit into
ClickHouse:masterfrom
jskong1124:fix-keeper-ipv6-fallback
Closed

jskong1124 wants to merge 1 commit into
ClickHouse:masterfrom
jskong1124:fix-keeper-ipv6-fallback

Conversation

@jskong1124

@jskong1124 jskong1124 commented Aug 12, 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 crashes on startup 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 PR aims to fix a crash that makes it difficult to run ClickHouse Keeper in some common enterprise environments.

On systems where IPv6 is disabled at the kernel level (like hardened RHEL 8 with ipv6.disable=1), ClickHouse Keeper currently fails to start. The logs show an Address family not supported by protocol error because Keeper tries to create an IPv6 Raft listener by default, and doesn't attempt to fall back to IPv4 when this fails.

This can be tricky to debug, and the only workaround is to use the <interserver_listen_host> setting, which isn't widely known.

I've added a simple fallback to make the startup process more robust.

The code will now first try to create the listener with its default behavior. If that fails (for instance, on an IPv4-only system), it will log a warning and automatically try again with an IPv4-only listener (0.0.0.0). The server only terminates if both attempts fail.

This change should allow Keeper to work smoothly out-of-the-box for more users, especially in environments where IPv6 is not available, without needing any special configuration.

Thank you for considering this contribution

The error log before this fix typically shows:

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

@CLAassistant

CLAassistant commented Aug 12, 2025 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@antonio2368 antonio2368 self-assigned this Aug 12, 2025

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

Why don't you just set keeper_server.enable_ipv6 to false?

@clickhouse-gh

clickhouse-gh Bot commented Aug 12, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8277d30]

Summary: ❌
15 failures out of 106 shown:

job_name test_name status info comment
Style check failure
cpp failure
Build (amd_debug) dropped
Build (amd_release) dropped
Build (amd_asan) dropped
Build (amd_tsan) dropped
Build (amd_msan) dropped
Build (amd_ubsan) dropped
Build (amd_binary) dropped
Build (arm_release) dropped
Build (arm_asan) dropped
Build (arm_coverage) dropped
Build (arm_binary) dropped
Build (amd_darwin) dropped
Build (arm_darwin) dropped
Build (arm_v80compat) dropped

Comment thread src/Coordination/KeeperServer.cpp Outdated

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.

Suggested change
asio_listener = asio_service->create_rpc_listener("0.0.0.0", state_manager->getPort(), logger);
asio_listener = asio_service->create_rpc_listener(state_manager->getPort(), logger, /*_enable_ipv6=*/false);

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

Copy link
Copy Markdown
Contributor Author

Hi @antonio2368, thanks for the review and the great suggestion!

You're right, that setting would have solved my issue. I wasn't aware of <enable_ipv6> until I dug deep into the source code. My initial approach was debugging from the error log (Address family not supported...), which didn't point to a specific config, so I thought a code-level fix would be the most robust solution for users who might run into the same problem.

I agree your suggested change to the code is much cleaner. I'll apply it right now. Thanks!

Comment thread src/Coordination/KeeperServer.cpp Outdated

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.

nit:
The throw Exception part can be added directly after the LOG_WARNING part, instead of judging if (!asio_listener) twice.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, thanks! I've pushed the change.

@jskong1124

Copy link
Copy Markdown
Contributor Author

Hi @superdiaodiao and @antonio2368,
It looks like the CI checks are failing because this PR needs the can be tested label.
Could one of you please add it when you have a moment?
Thanks for all your help!

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
failure [Config Workflow]
  failure [Pre Hooks]
    failure [can_be_trusted]
      | 'can be tested' label is required
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

@antonio2368 antonio2368 added the can be tested Allows running workflows for external contributors label Aug 13, 2025
@jskong1124

Copy link
Copy Markdown
Contributor Author

Hi @superdiaodiao and @antonio2368,

It seems the CI is now failing the new_tests_check. I need to add a test case to verify this fix.

I've read the integration test guide (tests/integration/README.md), but I'm still not confident about how to properly set up an IPv4 only Docker environment for the test.

Could you please point me to a good example test file that I could use as a template, or provide some guidance on how to best approach this? Any help would be greatly appreciated.
Thanks!

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
failure [Finish Workflow]
  failure [Post Hooks]
    failure [python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py]
      | No new tests have been added
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

@jskong1124

Copy link
Copy Markdown
Contributor Author

Hi @superdiaodiao and @antonio2368

I've added a new integration test, test_keeper_ipv4_fallback, to address the new_tests_check failure.
I did my best to follow the guide, but I couldn't verify it on my local Windows environment. Could you please take a look and help me get this through CI?

Thanks for your help!

Comment on lines +531 to +533
asio_listener = asio_service->create_rpc_listener(state_manager->getPort(), logger, /*_enable_ipv6=*/false);

if (!asio_listener)

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.

please replace tabs with spaces

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.

what are these added files?

where IPv6 is disabled via kernel sysctls. This confirms that the
IPv4 fallback logic for the Raft listener is working correctly.
"""
assert keeper_node.query("ruok") == "imok\n"

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.

how does this test what the comments says?

@jskong1124 jskong1124 closed this Aug 13, 2025
@jskong1124
jskong1124 deleted the fix-keeper-ipv6-fallback branch August 13, 2025 16:41
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants