Repository navigation
Fix gRPC and Arrow Flight listeners for wildcard listen hosts - #115074
Conversation
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.
|
Workflow [PR], commit [a90949c] Summary: ✅
AI ReviewSummaryThis PR fixes the wildcard-host overlap for Findings
Final VerdictChanges requested: the runtime LLVM Coverage ReportMeasured on commit a90949c.
Changed lines: Changed C/C++ lines covered: 106/119 (89.08%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
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 units15 translation units recompiled, 62 s compile time in total, 15 of them have a recent master baseline. |
`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.
|
🕵 @groeneai, the two remaining CI failures look unrelated to this PR (it only touches
The branch was merged with |
|
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 #113242 is sequenced behind #113735: its only functional red is |
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Not necessary. Postpone it.
gRPCtreats::and0.0.0.0as one family-agnostic wildcard: for either of them it binds a dual-stack::socket, and falls back to0.0.0.0only on a host without IPv6 (seeadd_wildcard_addrs_to_serverincontrib/grpc). Listing both wildcard addresses inlisten_hosttherefore made ClickHouse create two listeners that bind the very same socket address, and the second one eitherEADDRINUSE, because the Arrow Flight transport disablesSO_REUSEPORT, and the exception terminated the whole server:SO_REUSEPORTenabled, so each of the two independent servers ended up serving a random half of the connections, and a listener configured for0.0.0.0accepted IPv6 connections as well:Only one gRPC and one Arrow Flight listener is created for a group of wildcard
listen_hostvalues now, which is what the transport does internally anyway.Also,
listen_tryis honored for the protocols that bind their listening socket when they are started rather than when they are created.EADDRINUSEfrom gRPC or Arrow Flight was reported from the plainserver.start()loop, outside of thecreateServerhandler that implementslisten_try, so it was fatal even withlisten_try(and withlisten_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_REUSEPORTenabled, so a gRPC port that is already taken by a different process is silently shared instead of reported. Making that consistent withlisten_reuse_portfor both gRPC and Arrow Flight is a possible follow-up.For the record, gRPC and Arrow Flight are not available as composable protocols (the
protocolssection): the composable stack is a PocoTCPServerwith a chain ofTCPServerConnectionFactorylayers 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 undertls/proxy1.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix the server failing to start when
listen_hostcontains both::and0.0.0.0andarrowflight_portis configured, and fix two gRPC listeners silently sharing one port in the same configuration.listen_trynow 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
26.9.1.311(included in26.9and later)