Skip to content

Fix gRPC and Arrow Flight listeners for wildcard listen hosts - #115074

Merged
alexey-milovidov merged 16 commits into
masterfrom
grpc-arrowflight-wildcard-listen
Aug 29, 2026
Merged

alexey-milovidov merged 16 commits into
masterfrom
grpc-arrowflight-wildcard-listen

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 17, 2026 •

Copy link
Copy Markdown
Member

gRPC treats :: and 0.0.0.0 as one family-agnostic wildcard: for either of them it binds a dual-stack :: socket, and falls back to 0.0.0.0 only on a host without IPv6 (see add_wildcard_addrs_to_server in contrib/grpc). Listing both wildcard addresses in listen_host therefore made ClickHouse create two listeners that bind the very same socket address, and the second one either

  • failed with EADDRINUSE, because the Arrow Flight transport disables SO_REUSEPORT, and the exception terminated the whole server:
    <Error> grpc: Failed to add port to server: No address added out of total 1 resolved for '0.0.0.0:9110'
    (Failed to add any wildcard listeners: Error in bind for address '[::]:9110': Address already in use
    Error in bind for address '0.0.0.0:9110': Address already in use)
    <Error> Application: Code: 1002. DB::Exception: Failed init Arrow Flight Server: Unknown error: Server did not start properly.
    
  • or silently shared the port with the first one, because plain gRPC keeps SO_REUSEPORT enabled, so each of the two independent servers ended up serving a random half of the connections, and a listener configured for 0.0.0.0 accepted IPv6 connections as well:
    <Information> Application: Listening for gRPC protocol: [::]:9100
    <Information> Application: Listening for gRPC protocol: 0.0.0.0:9100
    LISTEN 0 4096 *:9100 users:(("clickhouse",pid=3851032,fd=55))
    LISTEN 0 4096 *:9100 users:(("clickhouse",pid=3851032,fd=56))
    

Only one gRPC and one Arrow Flight listener is created for a group of wildcard listen_host values now, which is what the transport does internally anyway.

Also, listen_try is honored for the protocols that bind their listening socket when they are started rather than when they are created. EADDRINUSE from gRPC or Arrow Flight was reported from the plain server.start() loop, outside of the createServer handler that implements listen_try, so it was fatal even with listen_try (and with listen_reuse_port) enabled - which contradicts the documented behavior of listening to at least one of the addresses without quitting.

Not addressed here: plain gRPC still keeps SO_REUSEPORT enabled, so a gRPC port that is already taken by a different process is silently shared instead of reported. Making that consistent with listen_reuse_port for both gRPC and Arrow Flight is a possible follow-up.

For the record, gRPC and Arrow Flight are not available as composable protocols (the protocols section): the composable stack is a Poco TCPServer with a chain of TCPServerConnectionFactory layers that receive an already accepted socket, while gRPC and Arrow Flight own the listening socket, the HTTP/2 framing, TLS and their own event loop, so they can neither be a layer nor sit under tls / proxy1.

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

Fix the server failing to start when listen_host contains both :: and 0.0.0.0 and arrowflight_port is configured, and fix two gRPC listeners silently sharing one port in the same configuration. listen_try now also covers the gRPC and Arrow Flight protocols, which bind their listening socket when they are started.


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

Version info

  • Merged into: 26.9.1.311 (included in 26.9 and later)

gRPC treats `::` and `0.0.0.0` as one family-agnostic wildcard: for either of them it binds a
dual-stack `::` socket and falls back to `0.0.0.0` only on a host without IPv6 (see
`add_wildcard_addrs_to_server` in `contrib/grpc`). Listing both wildcard addresses in `listen_host`
therefore made ClickHouse create two listeners that bind the very same socket address, and the
second one either

- failed with `EADDRINUSE`, because the Arrow Flight transport disables `SO_REUSEPORT`, and the
  exception terminated the whole server, or
- silently shared the port with the first one, because plain gRPC keeps `SO_REUSEPORT` enabled, so
  each of the two independent servers ended up serving a random half of the connections, and a
  listener configured for `0.0.0.0` accepted IPv6 connections as well.

Only one gRPC and one Arrow Flight listener is created for a group of wildcard `listen_host` values
now.

Also, `listen_try` is honored for the protocols that bind their listening socket when they are
started rather than when they are created. `EADDRINUSE` from gRPC or Arrow Flight was reported from
the plain `server.start()` loop, outside of the `createServer` handler that implements `listen_try`,
so it was fatal even with `listen_try` (and with `listen_reuse_port`) enabled, which contradicts the
documented behavior of listening to at least one of the addresses without quitting.
@clickhouse-gh

clickhouse-gh Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a90949c]

Summary: ✅


AI Review

Summary

This PR fixes the wildcard-host overlap for gRPC and Arrow Flight and closes most of the delayed-bind listen_try gaps. The remaining issue is the runtime SYSTEM START LISTEN lifecycle path: it now reads the reloaded config, but it can still return success after every requested delayed-bind listener was dropped, leaving the port down.

Findings

⚠️ Majors

  • [programs/server/Server.cpp:3408] SYSTEM START LISTEN does not verify that any delayed-bind listener actually survived listen_try. With only unavailable listen_host values, DB::createServer logs away the NETWORK_ERROR, returns false, and the callback still succeeds, so SYSTEM START LISTEN GRPC or SYSTEM START LISTEN ARROW FLIGHT can claim success while starting nothing.
    Suggested fix: compare the number of active listeners matching server_type before and after createServers (or return an explicit "started something" result) and throw when a non-no-op start request leaves that count at zero. Add a focused regression test for the all-fail listen_try case on the runtime start-listener path.
Final Verdict

Changes requested: the runtime SYSTEM START LISTEN path still hides an all-fail delayed-bind start under listen_try.

LLVM Coverage Report

Measured on commit a90949c.

Metric Baseline Current Δ
Lines 88.40% 88.40% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 80.70% 80.80% +0.10%

Changed lines: Changed C/C++ lines covered: 106/119 (89.08%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 17, 2026
Comment thread src/Server/createServer.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

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

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 712.38 MiB 709.33 MiB -3.05 MiB (-0.43%)

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.

Compile time of recompiled translation units

15 translation units recompiled, 62 s compile time in total, 15 of them have a recent master baseline.

Job report

Comment thread src/Server/createServer.cpp Resolved
Comment thread src/Server/createServer.cpp Resolved
Comment thread src/Server/createServer.cpp Resolved
Comment thread programs/server/Server.cpp Resolved
Comment thread programs/server/Server.cpp Resolved
`createServers` bound a throwaway Poco `ServerSocket` for `arrowflight_port`
before creating the listener, although gRPC owns the listening socket of an
Arrow Flight server and binds it in `ArrowFlightServer::start`.

That pre-bind defeats the family-agnostic wildcard handling of gRPC: with
`listen_host` values `::` and `0.0.0.0` the normalization keeps only `::`, and
on a host without IPv6 the pre-bind of `::` throws, so `listen_try` dropped the
Arrow Flight listener even though gRPC itself would have fallen back to
`0.0.0.0`. It also bound the address twice, which is a race of its own.

Fix the integration test configurations as well: a `listen_host` list where a
wildcard follows a specific address makes the plain Poco listeners for the
wildcard fail with `EADDRINUSE`, which left the container unreachable, and the
`listen_try` and runtime reload cases need a `listen_host` list without a
wildcard - the container hostname is used for that.
The reload regression only checked the log, which is also satisfied by a
broken reload that keeps the old specific listener and merely adds the
wildcard one next to it - the initial startup line is still in the log.
It also stopped exercising `Arrow Flight` on the `SYSTEM RELOAD CONFIG`
path.

The test now reads the live listening sockets from `/proc/net/tcp` and
`/proc/net/tcp6` inside the container, so it observes that the specific
address is gone and a single wildcard socket serves the port, and it
reloads an `arrowflight_port` in the same scenario. The `Arrow Flight`
port changes with the reload because `updateServers` destroys the old
listener only after `createServers` has bound the new one, and an
`Arrow Flight` socket - unlike a plain gRPC one - is not bound with
`SO_REUSEPORT`, so it cannot be rebound on the same port within a single
reload.
gRPC binds an `AF_INET6` socket with an IPv4-mapped address even for an
IPv4 `listen_host`, so the socket shows up in `/proc/net/tcp6` as
`::ffff:172.16.1.2`. Normalize that to the IPv4 form, and accept either
wildcard address for the normalized listener, matching the
family-agnostic wildcard handling of the server.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, the two remaining CI failures look unrelated to this PR (it only touches gRPC/Arrow Flight listener creation):

The branch was merged with master and the reload regression test was strengthened, so a fresh run will re-check both.

Comment thread src/Server/createServer.cpp Resolved
@groeneai

Copy link
Copy Markdown
Collaborator

The fix in progress for #115455 is #113242 ("Do not push sorting into Merge children across an order-breaking cast"); the arm_tsan stack on this PR reaches DistinctSortedStreamTransform.cpp:184 through getEqualRangeEndAssumeSorted with no ARRAY JOIN frame, so it is that Merge-child cast mechanism and not the stale sort-property variant of #110778.

#113242 is sequenced behind #113735: its only functional red is Fast test / 00717_merge_and_distributed, the pre-existing _table prefilter defect, and making that green in place would need conversionPreservesOrder to accept UInt64 -> Int64, the exact order-breaking conversion #113242 exists to refuse. With the review fix and the deflake now on #113735, once it lands I merge master into #113242, 00717 goes green on its own, and I re-push.

The start-listeners callback passed the startup snapshot of
`server_settings`, `listen_hosts`, and `listen_try` to `createServers`,
so after `SYSTEM RELOAD CONFIG` changed the listener configuration,
`SYSTEM STOP LISTEN` followed by `SYSTEM START LISTEN` recreated the
listener with the old host set and the old `listen_try` policy.
Recompute all three from the current `config()` inside the callback,
the same way `updateServers` does on reload.

Add an integration test: after a reload replaces the specific
`listen_host` with a wildcard, a gRPC stop/start cycle must come back
with the wildcard listener rather than the original specific address.

Co-Authored-By: Claude Fable 5 <[email protected]>
/// configuration from the current config instead of the startup snapshot.
ServerSettings current_server_settings;
current_server_settings.loadSettingsFromConfig(config());
createServers(

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.

SYSTEM START LISTEN still reports success when every delayed-bind listener is dropped under listen_try. This callback now reloads the current config, but after createServers(...) it never verifies that the requested server type ended up with any active listener.

Concrete trace: reload to <listen_host>192.0.2.1</listen_host>, <listen_try>1</listen_try>, and <grpc_port>9100</grpc_port>, run SYSTEM STOP LISTEN GRPC, then SYSTEM START LISTEN GRPC. DB::createServer swallows the NETWORK_ERROR, returns false, and this callback returns successfully even though grpc_port is still down. The same gap exists for Arrow Flight.

Please snapshot the number of active listeners matching server_type before and after createServers (or otherwise surface whether any delayed-bind listener actually survived) and throw when a non-no-op SYSTEM START LISTEN request leaves that count at zero. A focused regression case with only unavailable listen_host values and listen_try=1 on this lifecycle path would pin it down.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not necessary. Postpone it.

@alexey-milovidov alexey-milovidov self-assigned this Aug 29, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 29, 2026
Merged via the queue into master with commit c0938b0 Aug 29, 2026
179 checks passed
@alexey-milovidov
alexey-milovidov deleted the grpc-arrowflight-wildcard-listen branch August 29, 2026 02:54
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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