Repository navigation
Fix e2e port startup races - #433
Conversation
PaxMachinaOne
left a comment
There was a problem hiding this comment.
PaxMachina review for human approval (987 changed lines)
Head 8d8b061c228f · Base 474d3745f083
-
High — e2e package likely no longer compiles.
test/e2e/broker_start.go:85,131,166is a non-test source file but depends onbrokerLogBuffer, whose implementation remains intest/e2e/consumer_group_persistence_test.go:192. Regular package files cannot depend on declarations available only from_test.gofiles. Move the buffer type into a non-test helper file or renamebroker_start.gotobroker_start_test.go. Verify withgo test -tags=e2e ./test/e2e. -
Medium — snapshot repair fails when the advertised host differs from the listen host.
test/e2e/broker_start.go:216-220only matches snapshot brokers whose host equalsoldHost, then replaces the host with the new listen host. WithKAFSCALE_BROKER_HOST=host.docker.internal, snapshots advertise that hostname whileoldis typically127.0.0.1:port; no broker is matched, leaving the collided port in metadata. If matched by another mechanism, replacing the advertised host with127.0.0.1would also break Docker clients. Preserve the snapshot’s advertised host and update the intended broker’s port, preferably identifying it by broker ID. The auxiliary-listener test attest/e2e/broker_start_test.go:226-265passes no etcd endpoints and therefore does not cover this interaction. -
Medium — auxiliary-listener readiness can still accept a failed startup.
test/e2e/broker_start.go:188-197treats two successful TCP polling rounds, only about 20ms apart, as sufficient. An already-occupied metrics/control port itself satisfies the probe; if the broker’s asynchronous bind-error log is delayed beyond those rounds, startup returns success and no retry occurs. Use an explicit readiness signal for each broker-owned listener or wait for a meaningful stability period/process status rather than relying on connectivity to addresses that may belong to another process.
Diff-only limits: I could not confirm whether another non-test definition of brokerLogBuffer exists outside the supplied diff, nor inspect broker log formats/startup ordering or all unchanged call sites. A human should grep every startBrokerWithEtcd/startBrokerProcess call, run the tagged package build plus the new race suite repeatedly, and exercise collision retries with both etcd and KAFSCALE_BROKER_HOST configured.
Human approval and merge required.
PaxMachinaOne
left a comment
There was a problem hiding this comment.
Two material test-harness gaps remain on this exact head:
-
Snapshot repair misses advertised-host configurations.
moveSnapshotBrokerAddressmatches the persisted broker by the old listen host and then replaces its host with the new listen host. WithKAFSCALE_BROKER_HOST=host.docker.internal, the snapshot contains that advertised hostname while the old listen address is127.0.0.1:PORT, so no row matches and the collided port remains persisted. Matching the intended broker by broker ID and updating only its port would preserve the advertised host. The current auxiliary-listener regression passes no etcd endpoints, so it does not cover this combination. -
Metrics readiness can still accept the process that stole the port. Metrics binding runs asynchronously.
waitBrokerStartuptreats two successful TCP dials roughly 20 ms apart as ownership, but an unrelated process already holding the metrics port satisfies both probes. If the broker's asynchronousmetrics server errorlog is delayed beyond those polls, the helper returns success instead of retrying. Probe a broker-specific HTTP endpoint/response or add an explicit listener-owned readiness signal.
The automated review's package-compilation finding is not valid: go test -race -tags=e2e ./test/e2e and the exact startup regression suite compile and pass. All hosted checks are green.
PaxMachinaOne
left a comment
There was a problem hiding this comment.
Re-reviewed the updated exact head. Both prior findings are fixed: snapshot repair now identifies the intended broker by ID and updates only its port, preserving advertised hosts and unrelated broker entries; auxiliary readiness now requires this child's successful metrics bind marker plus the expected broker metrics payload, so an unrelated listener cannot satisfy startup. The expanded advertised-host, delayed-bind, retry, cancellation, and process-reaping regressions are sound. The startup suite passed three consecutive -race runs, the full broker race suite passed, and all hosted CI/CodeQL checks are green. No material findings.
Summary
Embedded etcd binds client and peer listeners directly on
127.0.0.1:0, removing the pick-then-bind window behind the coordinator-crash flake.Broker fixtures share startup handling with at most three attempts, retrying only address-in-use failures with fresh Kafka, metrics and control ports. Callers use the actual endpoints. Snapshot repair selects the broker by its effective broker ID and updates only its port, preserving advertised hostnames and other broker entries with CAS. Failed children are reaped before retrying, and cancellation stops the whole process group.
Metrics startup emits a signal after successfully binding its listener. The harness enables debug logging and requires that signal from its own child plus a valid broker HTTP metrics payload. An unrelated listener, including one serving another broker's metrics, cannot satisfy readiness while the child's bind failure is delayed.
Adds forced collision, retry-limit, advertised-host metadata, delayed metrics failure and cleanup regressions to Kafka CI, plus developer instructions for repeated runs. The only broker change makes the existing asynchronous metrics bind explicit and logs its successful address before serving.
Closes #423.
Testing
-race(189s), including both review regressions.-race.go vet -tags=e2e ./test/e2e ./cmd/broker, formatting, license headers and patch whitespace.-race.-race.make commit-checktest gates: Go race tests, chart checks, 100% authentication coverage, nested modules, both JavaScript SDK suites and fuzz tests passed.Docker/MinIO-dependent CLI and S3 fixtures compile but were not run locally because Docker is unavailable. Hosted Kafka CI passed on this exact commit, including the expanded startup suite, proxy, librdkafka, coordinator recovery and Docker Kafka CLI tests. Current CI has 21 successful checks, two expected skips and operator snapshot/HA still running.
Checklist