mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-19 20:44:28 +02:00
* 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.
74 lines
2.5 KiB
Go
74 lines
2.5 KiB
Go
package testutil
|
|
|
|
import "testing"
|
|
|
|
// AllocateMiniPorts must never hand out a port that weed mini will reserve
|
|
// for one of its default services (or that default's gRPC offset). A real
|
|
// failure: Filer was given 22535 (Admin default 12535 + GrpcPortOffset),
|
|
// which mini then refused as "reserved for gRPC calculation".
|
|
func TestAllocateMiniPortsAvoidsMiniDefaults(t *testing.T) {
|
|
reserved := reservedMiniPorts()
|
|
for iter := 0; iter < 200; iter++ {
|
|
ports, err := AllocateMiniPorts(4)
|
|
if err != nil {
|
|
t.Fatalf("iter %d: AllocateMiniPorts: %v", iter, err)
|
|
}
|
|
for _, p := range ports {
|
|
if reserved[p] {
|
|
t.Fatalf("iter %d: allocated port %d is a mini default (or gRPC offset)", iter, p)
|
|
}
|
|
if reserved[p+GrpcPortOffset] {
|
|
t.Fatalf("iter %d: allocated port %d has gRPC offset %d colliding with a mini default",
|
|
iter, p, p+GrpcPortOffset)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// AllocateMiniPorts must keep every port it hands out, and that port's gRPC
|
|
// counterpart, below 32768 - the Linux default ip_local_port_range floor.
|
|
// A real failure: filer was allocated 44204, then lost the bind to a transient
|
|
// outbound connection that had grabbed 44204 as an ephemeral source port
|
|
// during mini startup ("bind: address already in use").
|
|
func TestAllocateMiniPortsBelowEphemeralFloor(t *testing.T) {
|
|
const ephemeralFloor = linuxEphemeralPortFloor
|
|
for iter := 0; iter < 200; iter++ {
|
|
ports, err := AllocateMiniPorts(4)
|
|
if err != nil {
|
|
t.Fatalf("iter %d: AllocateMiniPorts: %v", iter, err)
|
|
}
|
|
for _, p := range ports {
|
|
if p+GrpcPortOffset >= ephemeralFloor {
|
|
t.Fatalf("iter %d: port %d (gRPC %d) reaches the ephemeral range floor %d",
|
|
iter, p, p+GrpcPortOffset, ephemeralFloor)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAllocatePortSetNoGrpcCollision(t *testing.T) {
|
|
// Run a few iterations to catch the OS-recycles-just-closed-port race
|
|
// that previously hit regular ports when the mini gRPC offset was freed
|
|
// between AllocateMiniPorts and AllocatePorts calls.
|
|
for iter := 0; iter < 20; iter++ {
|
|
mini, regular, err := AllocatePortSet(1, 3)
|
|
if err != nil {
|
|
t.Fatalf("iter %d: AllocatePortSet: %v", iter, err)
|
|
}
|
|
if len(mini) != 1 || len(regular) != 3 {
|
|
t.Fatalf("iter %d: unexpected counts mini=%d regular=%d", iter, len(mini), len(regular))
|
|
}
|
|
reserved := map[int]bool{
|
|
mini[0]: true,
|
|
mini[0] + GrpcPortOffset: true,
|
|
}
|
|
for _, p := range regular {
|
|
if reserved[p] {
|
|
t.Fatalf("iter %d: regular port %d collides with mini pair %d/%d",
|
|
iter, p, mini[0], mini[0]+GrpcPortOffset)
|
|
}
|
|
reserved[p] = true
|
|
}
|
|
}
|
|
}
|