Skip to content

Keep the SeaweedFS mini admin gRPC port out of the ephemeral range - #115512

Merged
azat merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-seaweedfs-mini-admin-port-ephemeral
Aug 20, 2026
Merged

azat merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-seaweedfs-mini-admin-port-ephemeral

Conversation

@groeneai

@groeneai groeneai commented Aug 19, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #109368
Related: seaweedfs/seaweedfs#10838

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

...

Description

test_database_iceberg_seaweedfs_catalog can fail in fixture setup with a Connection refused reading
as "the catalog never started"
(report,
tagged retry_ok). It did start: it answered 200 on all 314 polls; the refusal is the last poll,
after the container exited 255. Its log shows why.

E mini.go:1583 Admin server error: failed to listen on port 33646: bind: address already in use
F mini.go:1598 Admin server readiness check failed ... after 240 attempts

weed mini derives the admin gRPC port as admin.port + 10000 = 33646, inside the Linux ephemeral
range (floor 32768), so one of mini's own startup dials can take it as a source port before admin
binds it. It is the only derived gRPC port above the floor; the other four land in 18333..19340.

The failure hides itself: glog.Fatalf skips defer close(allServicesReady), and the call creating
-tableBucket=analytics runs only after <-allServicesReady. S3 and Iceberg keep answering 200
while analytics is never created, so "analytics" in buckets never becomes true and a longer wait
cannot help.

-admin.port=12646 derives 22646: below the floor, and below the 22768 cap SeaweedFS derives for
this same problem in its own test port allocator (seaweedfs/seaweedfs#10209, which left the mini
default alone). That default is 23646 on 4.41, 4.42 and master, so an image bump does not help; it is
filed upstream. Raising ip_local_port_range via sysctls, as the Kafka composes do, would work too,
but for every dial mini makes.

It reaches users too: the SeaweedFS catalog guide and connector page both document mini on
image: latest, so the bucket each tells the reader to use never appears. Both are pinned here;
the guide's locale copies are left to the translation workflow.

Validated with docker run --sysctl net.ipv4.ip_local_port_range="33646 33646": unpinned reproduces
the CI log verbatim, pinned creates the bucket, a default-range control is green.


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

Version info

  • Merged into: 26.8.1.1762 (included in 26.8 and later)
  • Backported to: 26.7.7.71, 26.6.5.102

test_database_iceberg_seaweedfs_catalog could fail during fixture setup with a
Connection refused from wait_for_seaweedfs, which reads as "the Iceberg REST
catalog never started". That reading is wrong: the catalog answered HTTP 200 on
all 314 polls, and the Connection refused was only the final poll, issued after
the container had already exited 255.

weed mini derives its admin gRPC port as admin.port + 10000, i.e. 23646 + 10000
= 33646, which is inside the Linux ephemeral range (floor 32768). One of mini's
own startup dials can therefore take 33646 as an outbound source port before the
admin server binds it, and the listen fails with "bind: address already in use"
(mini.go:1583). Admin is the only derived gRPC port above the floor: mini derives
exactly five of them (master 19333, filer 18888, volume 19340, s3 18333, admin
33646), and WebDAV and Iceberg carry a null gRPC pointer so they derive nothing.

The failure then masks itself. glog.Fatalf (mini.go:1598) skips
defer close(allServicesReady), and ensureMiniTableBuckets, which creates
-tableBucket=analytics, runs only after <-allServicesReady. So the Iceberg
service keeps answering 200 while the analytics bucket is never created, and the
fixture's "analytics" in buckets condition can never become true.

Pinning -admin.port=12646 makes the derived port 22646: below the ephemeral
floor, and below the 22768 cap SeaweedFS uses for this same problem in its own
test port allocator (seaweedfs/seaweedfs#10209, which left the mini default
alone). The default is still 23646 on tags 4.41, 4.42 and upstream master, so
bumping the image does not help. -admin.ui=false does not help either:
startMiniAdminWithWorker is launched unconditionally and miniEnableAdminUI only
affects the welcome banner. Extending the fixture wait cannot help, because the
container is dead and the bucket is never created.

Validated by forcing the collision with
docker run --sysctl net.ipv4.ip_local_port_range="33646 33646" on
chrislusf/seaweedfs:4.41: without the pin the CI log reproduces verbatim at both
mini.go:1583 and mini.go:1598 including the two-minute readiness gap, and the
analytics bucket is never created; with the pin it is. A control run on the
default range passes unpinned, so the harness is not trivially red. The
integration test itself passes and its container log reports
Admin UI: ...:12646, where the same run on unpinned master reports ...:23646.

The other SeaweedFS entry point, ci/jobs/scripts/functional_tests/
setup_seaweedfs.sh, needs no change: it runs weed server, which has no admin
server, and already pins ports deriving to 21111..21114.

The same collision reaches users through the two documented setups, so they are
pinned as well: the SeaweedFS catalog guide's docker-compose.yml and the
SeaweedFS connector page's docker run. Both pin image :latest, and admin.port is
still 23646 there. Their symptom is worse than the test's, because the bucket
each page tells the reader to use is the one that is never created, while the
container keeps answering HTTP 200: the guide's CREATE DATABASE against
s3://analytics and the connector page's clickhouse bucket both fail against a
container that looks healthy. Verified on chrislusf/seaweedfs:latest with the
same forced collision, once per page: unpinned, neither "created bucket
clickhouse" nor "created table bucket analytics" appears and the container exits
255; pinned, each bucket is created and the container reports
Admin UI: ...:12646. Both snippets keep publishing only 8333 and 8181, so the
pinned admin port stays inside the container.

The eight locale copies of the guide are left alone: they are generated from the
English source (docs/README.md), so editing them by hand would be overwritten.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109368&sha=4443610796f2ef985ff5615a261456a7ea4155ea&name_0=PR&name_1=Integration%20tests%20%28amd_tsan%2C%205%2F6%29
Related: ClickHouse#109368
Upstream: seaweedfs/seaweedfs#10838
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Aug 19, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (click to expand)

Three review rounds, an independent cold review plus a second-model gate each round. The final
round is clean: the gate returned no findings. Findings and verdicts:

⚠️ The user-facing setups had the same defect. The SeaweedFS catalog guide and the SeaweedFS
connector page both document mini on image: latest, where admin.port is still 23646. Their
symptom is worse than the test's: the bucket each page tells the reader to create never appears
while the container keeps answering HTTP 200. Both pinned. Verified on chrislusf/seaweedfs:latest
with the same forced collision, once per page: unpinned, the bucket is never created and the
container exits 255; pinned, it is created. The guide's eight generated locale copies are left to
the translation workflow.

⚠️ A false countable claim about upstream internals. An earlier draft said mini derives six
gRPC ports and listed webdav 17333. WebDAV derives nothing: it is registered with a null gRPC
pointer, has no gRPC port field, and is absent from initializeGrpcPortsOnIP, which derives
exactly master 19333, filer 18888, volume 19340, s3 18333 and admin 33646. Corrected; the
conclusion is unchanged, since admin is still the only one above 32768.

💡 -admin.port is the right flag rather than -admin.port.grpc. admin.port is in
portFlagNames, so an explicitly passed value is honoured and a conflict fails loudly
(ensurePortAvailableOnIP returns an error, runMini exits 1) instead of being silently
relocated with a warning, which is what the default path does.

💡 Two refutations recorded rather than assumed. An image bump cannot fix this: the 23646
default is identical on 4.41, 4.42 and upstream master, all three read. -admin.ui=false cannot
either: startMiniAdminWithWorker is launched unconditionally and the flag only affects the
welcome banner.

💡 The magic port is now explained on both docs pages, since each page explains every other
flag it displays.

💡 No new ClickHouse test, and none is constructible. The condition is a third-party
container's port derivation with no ClickHouse-side observable; the test has run 7652 OK / 1 FAIL
since it was added, and 675 master runs with 0 failures. The red/green oracle is the forced
--sysctl net.ipv4.ip_local_port_range="33646 33646" reproduction, in both directions with a
default-range control, so the harness is demonstrably not trivially red.

💡 Alternative considered and rejected: raising the container's ip_local_port_range via
sysctls, as the Kafka composes do. It works, but moves the range for every outbound dial mini
makes, where pinning one flag addresses the one port at fault.

Carriers enumerated independently: 11 mini invocations in the tree (this compose, two English
docs pages, eight generated locale copies). ci/jobs/scripts/functional_tests/setup_seaweedfs.sh
needs no change: it runs weed server, which has no admin server and already pins ports deriving
to 21111..21114.

Session id: cron:clickhouse-review-slot-8:20260819-202200

@groeneai groeneai added the groeneai-origin-request PR origin: a maintainer pinged or directed groeneai label Aug 19, 2026
@clickhouse-gh clickhouse-gh Bot closed this Aug 19, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Aug 19, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. docker run --rm --sysctl net.ipv4.ip_local_port_range="33646 33646" chrislusf/seaweedfs:4.41 mini -dir=/data -s3 -s3.config=/etc/seaweedfs/s3.json -tableBucket=analytics fails on every run, reproducing the CI log verbatim at both mini.go:1583 and mini.go:1598 plus the 2-minute readiness gap.
b Root cause explained? Yes. weed mini derives its admin gRPC port as admin.port + 10000 = 33646, which is inside the Linux ephemeral range (floor 32768), so one of mini's own startup dials can take it as an outbound source port before the admin server binds it. glog.Fatalf then skips defer close(allServicesReady), and the call creating -tableBucket=analytics runs only after <-allServicesReady, so the Iceberg service keeps answering 200 while the analytics bucket is never created and the fixture's "analytics" in buckets condition can never become true. The visible Connection refused is only the final poll after the container exits 255.
c Fix matches root cause? Yes. Pinning -admin.port=12646 makes the derived port 22646, below the ephemeral floor, so the collision window ceases to exist. It is not a wait extension or a retry: the container was dead and the bucket never created, so no amount of waiting could succeed.
d Test intent preserved / new tests added? Preserved. The only change to the test path is the sidecar container's admin port; no assertion, dataset or timeout is touched, and wait_for_seaweedfs still requires both a 200 and the analytics bucket. No new test: the condition is a third-party container's port derivation, which no ClickHouse-level test can assert.
e Both directions demonstrated? Yes, twice. Raw container, collision forced: without the pin created table bucket analytics=0 and readiness check failed=1 (exit 255); with the pin 1 and 0. Real fixture: passes and logs Admin UI: ...:12646, where the same fixture on unpinned master logs ...:23646. A default-range control passes unpinned, so the harness is not trivially red.
f Fix is general across code paths? Yes. The repo has 11 mini invocations: this compose file plus two English docs pages, all three pinned here, and eight generated locale copies of the guide, which are regenerated from the English source and are not hand-edited (docs/README.md:61). The other SeaweedFS entry point, ci/jobs/scripts/functional_tests/setup_seaweedfs.sh, runs weed server, which starts no admin server (weed/command/server.go has no admin service or admin.port flag; its one admin occurrence is an unrelated flag description), and already pins ports deriving to 21111..21114.
g Fix generalizes across inputs? Yes for the invariant at issue: every port mini derives by adding 10000 must stay below the ephemeral floor. initializeGrpcPortsOnIP derives exactly five: master 19333, volume 19340, filer 18888, s3 18333 were already below it; admin was the only one above. WebDAV and Iceberg carry a null gRPC pointer and derive nothing. 22646 collides with no port mini uses and sits outside the 23647..23746 admin fallback scan window. admin.port still defaults to 23646 on 4.41, 4.42 and upstream master, so the same pin is required for the :latest the docs pages use, not only for the image CI pins.
h Backward compatible? N/A. Test infrastructure only: no setting, no serialization format, no SettingsChangesHistory.cpp entry, no experimental gate.
i Invariants and contracts preserved? Yes. The compose file still starts the same services with the same S3 credentials, and the published container port mapping (${ICEBERG_REST_CATALOG_PORT}:8181) and healthcheck are unchanged; only the admin service's own listen port moves, and 12646 is not published to the host. YAML parses and the added text is a shell comment inside the existing sh -c script body, after the heredoc terminator. The docs pages likewise publish only 8333 and 8181, so the pinned admin port stays container-local there too, and both snippets remain copy-pasteable as written.

Session id: cron:clickhouse-impl-slot-4:20260819-152200

@clickhouse-gh

clickhouse-gh Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1d9a61e]

Summary: ✅


AI Review

Summary

This PR pins -admin.port=12646 for the SeaweedFS mini setups used by the SeaweedFS Iceberg integration compose and the two English docs examples, so the derived admin gRPC port stays out of the Linux ephemeral range. I checked the current diff against the integration fixture and the remaining non-localized mini examples in the tree; the changed surface matches the stated contract, and I did not find a correctness, rollout, or documentation issue in the current head.

Final Verdict

✅ No findings.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 19, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @chrislusf @hanfei1991, could you review this? weed mini derives its admin gRPC port as admin.port + 10000 = 33646, which is inside the Linux ephemeral range, so one of mini's own startup dials can take it before the admin server binds it; pinning -admin.port=12646 keeps the derived port below the 32768 floor in the integration compose and in the two documented setups.

@chrislusf

Copy link
Copy Markdown
Contributor

This is a good fix. The other fix is to set -admin.port.grpc directly. Either way would work.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Both work. I picked -admin.port because it is the one listed in portFlagNames (weed/command/mini.go:1150, at the 4.41 tag the compose pins), so an explicitly passed value that is already taken returns an error at :835 and runMini exits 1 at :1200. -admin.port.grpc is not tracked there, so initializeGrpcPortsOnIP relocates it silently with only a Warningf at :1001. For a CI fixture I preferred the loud failure.

@clickhouse-gh

clickhouse-gh Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 1d9a61e42 with master 27f733d4f (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 703.88 MiB 700.84 MiB -3.04 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

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

Job report

@PedroTadim

Copy link
Copy Markdown
Member

cc @azat

@azat

azat commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

Ok, but @groeneai who asked you to create issue in upstream? Nobody. Please, before creating issues in upstream, wait for approval

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

Actually why it happens if we should have net.ipv4.ip_local_port_range: '55000 65535' ?

@groeneai

Copy link
Copy Markdown
Collaborator Author

Because that sysctl never reaches this container: it is per-netns, and the note you left at tests/integration/conftest.py:62 in 344d648 says so ("it is not inherited, so you may need to specify this in docker_compose_$SERVICE.yml"). Only 4 of the 56 files in tests/integration/compose/ carry a sysctls: block (kafka, kafka_sasl, kerberized_kafka, hdfs). docker_compose_iceberg_seaweedfs_catalog.yml is not one of them.

Measured on a box whose host range is 32768 60999:

  • docker run --rm chrislusf/seaweedfs:4.41 cat /proc/sys/net/ipv4/ip_local_port_range gives 32768 60999; with --sysctl net.ipv4.ip_local_port_range="55000 65535" it gives 55000 65535.
  • It is a kernel property, not a docker one: inside a container already set to 55000 65535, unshare -n cat /proc/sys/net/ipv4/ip_local_port_range returns 32768 60999.

So 33646 is ephemeral in the SeaweedFS netns, and weed mini dials its own services from there while starting up.

A sysctls: block on that service fixes the CI job too, and I will switch to it if you prefer consistency with the existing four. I used -admin.port because this PR also touches two docs call sites (a bare docker run and a standalone compose) where a CI-only sysctl is not available, so one flag covers all three identically.

On the upstream issue: understood, I should have asked first and will wait for approval before filing in a repo I do not own. seaweedfs/seaweedfs#10838 is open with no comments; tell me whether to close it and whether to keep the Related: line, and I will not touch either on my own.

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

Ok, let's go this way (not to spend more CI time)

@azat
azat added this pull request to the merge queue Aug 20, 2026
Merged via the queue into ClickHouse:master with commit 5e6ea9a Aug 20, 2026
356 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 20, 2026
@azat

azat commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

How it is possible if seaweedfs has been added only in 26.8? #113828

UPD: I removed the label

@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 10, 2026
PedroTadim pushed a commit that referenced this pull request Sep 10, 2026
…out of the ephemeral range

Conflict resolution: the two .mdx documentation files touched by the original
PR do not exist on the 26.7 release branch, so only the compose-file change
(pinning -admin.port=12646) is backported.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
PedroTadim pushed a commit that referenced this pull request Sep 10, 2026
…out of the ephemeral range

Conflict resolution: the two .mdx documentation files touched by the original
PR do not exist on the 26.6 release branch, so only the compose-file change
(pinning -admin.port=12646) is backported.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
PedroTadim added a commit that referenced this pull request Sep 10, 2026
Cherry pick #115512 to 26.7: Keep the SeaweedFS mini admin gRPC port out of the ephemeral range
PedroTadim added a commit that referenced this pull request Sep 10, 2026
Cherry pick #115512 to 26.6: Keep the SeaweedFS mini admin gRPC port out of the ephemeral range
robot-clickhouse added a commit that referenced this pull request Sep 10, 2026
robot-clickhouse added a commit that referenced this pull request Sep 10, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 10, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 10, 2026
Backport #115512 to 26.7: Keep the SeaweedFS mini admin gRPC port out of the ephemeral range
clickhouse-gh Bot added a commit that referenced this pull request Sep 10, 2026
Backport #115512 to 26.6: Keep the SeaweedFS mini admin gRPC port out of the ephemeral range
chrislusf added a commit to seaweedfs/seaweedfs that referenced this pull request Oct 19, 2026
…ener (#11816)

* admin: default to port 12535, keep 23646 as a best-effort compat listener

The default admin HTTP port 23646 derives a worker gRPC port of 33646
(port + GrpcPortOffset), inside the Linux default ephemeral range
(32768+). One of our own startup dials can claim 33646 before the admin
binds it, killing startup. This is the same failure #10209 fixed for
the test port allocator, still reachable via the mini default (#10838)
and via standalone `weed admin` defaults.

Move the default admin port to 12535 (gRPC 22535) everywhere, keeping
the http+10000 convention so worker -admin derivation, the Rust worker
and host:http.grpc addressing keep working:

- weed admin -port, weed mini -admin.port
- weed worker -admin, the plugin worker fallback, Rust worker and
  weed-lance-worker defaults
- help text, README, helm values, docker compose, tests

So old workers, bookmarks and scripts keep working, admin also serves
the same handler and the worker gRPC server on the previous default
(-port.legacy / -admin.port.legacy, default 23646, 0 disables). The
legacy gRPC port binds best-effort: it lives in the ephemeral range, so
a failed bind only warns instead of reintroducing the startup failure.
weed mini reserves it early like the primary port and keeps it out of
its own port relocation. grpc.Server tracks every listener handed to
Serve, so the compat listener stops with the primary.

Also warn when an explicitly configured admin port puts the derived
gRPC port at or above the ephemeral floor, the other fix suggested in
the issue.

Supersedes the pinned-grpc approach in #11814: pinning -admin.port.grpc
off the +10000 convention breaks external workers that derive the admin
gRPC port from the HTTP address. ClickHouse/ClickHouse#115512 pins
-admin.port on their side; this makes that pin unnecessary.

Fixes #10838

* admin: let services win the legacy ports, close compat listener on failure

Review findings on the compat listeners:

- Do not put the legacy ports in mini's reservedPorts: an explicit
  -s3.port=23646 or -master.port.grpc=33646 must be honored, not rejected
  or stolen by the early reservation. Mini now checks the finalized port
  set and skips only the conflicting compat listener, so HTTP and gRPC
  compat degrade independently and the service keeps its port.
- Also skip the legacy HTTP listener when a mini service owns the port:
  a wildcard-bound service can still leave loopback bindable, which would
  let the compat listener shadow it for loopback clients.
- Close legacyServer's raw listener in the deferred cleanup: Serve may
  not have registered it yet when startAdminServer returns early.
- Helm: add admin.legacyPort (default 23646) and expose the legacy
  http/grpc ports through the admin Service, container ports and
  NetworkPolicy so older workers resolved via the Service keep working.

* helm: only pass -port.legacy when it differs from the binary default

ct install deploys the released image with the new chart, and 4.48 does
not know -port.legacy, so the admin pod crash-loops. Omitting the flag at
the default value is behavior-identical on new binaries (their default
is also 23646) and keeps older releases installable; legacyPort: 0 or a
custom port still renders the flag.
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 groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-ci pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.5-must-backport v26.6-must-backport v26.7-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants