Skip to content

[Fix][Zeta] Isolate REST test HTTP ports from Hazelcast discovery - #13030

Merged
nzw921rx merged 2 commits into
apache:devfrom
DanielLeens:codex-ci-rest-http-port-isolation-20261028
Oct 31, 2026
Merged

nzw921rx merged 2 commits into
apache:devfrom
DanielLeens:codex-ci-rest-http-port-isolation-20261028

Conversation

@DanielLeens

Copy link
Copy Markdown
Contributor

Purpose of this pull request

Yes, I am contributing this test-fixture fix to Apache SeaTunnel.

Keep the HTTP listeners in two REST test fixtures outside their Hazelcast discovery ranges. Both failures occurred on October 27 in PRs that do not change these fixtures:

  • PR #13014, Windows JDK 17: OptionRulesApiTest starts Hazelcast at 18044, then repeatedly connects to its HTTP listener at 18082. It fails to join after 300 seconds.
  • PR #13011, Ubuntu JDK 11: RestApiSubmitJobStartWithSavePointTest starts Hazelcast at 22981, then repeatedly connects to HTTP port 23000, with the same startup failure.

#11630 (696e27422) introduced random Hazelcast ranges while leaving HTTP ports unreserved. #11572 (c7401bf14) subsequently moved allocation into 10000..30000, which contains both fixed HTTP ports. #11868 widened discovery from 30 to 100 ports: the observed OptionRules collision is 38 ports above its base, while the savepoint collision is 19 ports above its base and was already within the previous scan width. A distinct cluster name cannot prevent the wrong-protocol connection.

This patch uses the existing TestUtils allocator for both HTTP fixtures:

  • Reserve the single HTTP port used by OptionRulesApiTest before allocating its Hazelcast range.
  • Reserve two HTTP ports for the savepoint fixture's two members. They can share HttpConfig, so dynamic selection is retained. Jetty's upper endpoint is inclusive: a range of one covers exactly the two reserved ports. This replaces the unreserved 2,001-candidate range rather than reserving a large block in the shared test-port pool.

Related: #13028 addresses the same collision pattern in RestApiHttpsForTruststoreTest. This PR changes neither that fixture nor its branch.

Does this PR introduce any user-facing change?

No. Only two test fixtures change. Production code, shared allocator implementation, POMs, APIs, checkpoint formats, test methods, assertions, timeouts and Hazelcast discovery settings are unchanged.

How was this patch tested?

  • Passed scoped JDK 17 formatting: ./mvnw -f seatunnel-engine/seatunnel-engine-server/pom.xml -nsu -Dmaven.gitcommitid.skip=true spotless:apply spotless:check. git diff --check also passed.
  • An independent automated source review found no blocking findings in the final two-port variant. It covers allocator exclusion, static initialization order, shared HTTP configuration, Jetty's inclusive port-selection range and preservation of all existing assertions. The allocator is not an OS-level port reservation; external-process races remain outside this fix.
  • No local compilation, tests, E2E, Docker, services or UI were run; no build artifacts were reused. Runtime verification must come from the exact-head GitHub unit-test matrix, including both REST classes. CI results remain pending.
  • OptionRulesApiTest retains its exact REST status and option-rule checks. The savepoint test retains its two-member cluster check, missing-checkpoint HTTP 400 checks, restored job identifiers and restore-mode assertions.

Check list

  • No production code, dependency, connector registration or compatibility changes.
  • No disabled tests, removed assertions, or increased timeout/retry budgets.
  • No user-facing documentation change is needed.

@DanielLeens DanielLeens left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Review of 7bd50c98251346b2635880b70953cc5483fef033 — no blocking source findings. Merge remains blocked by queued current-head CI and required independent approval.

Basic information: [Fix][Zeta] Isolate REST test HTTP ports from Hazelcast discovery; author DanielLeens; target dev; +7/-3 across two existing test files. Report time: 2026-10-28 02:38:48 EDT (UTC-0400). Local branch codex-review-13030-20261028, worktree /Volumes/disk8/tmp/seatunnel-review-13030-20261028. This is an independent source inspection in the current audit; a COMMENT posted by the PR author account is not independent human approval.

What changes: two REST fixtures used HTTP listener ports inside the random Hazelcast allocation pool. For example, Hazelcast probing a 100-port range could reach an already-running HTTP listener and fail its protocol handshake. OptionRulesApiTest now reserves its one HTTP port through TestUtils. The savepoint fixture reserves two adjacent HTTP ports and limits dynamic selection to precisely those two ports.

Key findings:

  • OptionRulesApiTest.java:51-52 allocates HTTP before Hazelcast. TestUtils.getAvailablePort is synchronized, checks every recorded range for overlap, probes all requested ports, and records the complete inclusive allocation. The one HTTP port therefore cannot be inside this fixture's 100-port Hazelcast range.
  • RestApiSubmitJobStartWithSavePointTest.java:78-80,96-101,443-447 allocates Hazelcast first and reserves a two-port HTTP range before either member starts. EngineConfig can use the shared default HttpConfig from ServerConfigOptions.MasterServerConfigOptions.HTTP; configuring the worker can therefore also enable HTTP on the master. Reserving two ports is necessary. JettyService.chooseAppropriatePort uses port <= initialPort + portRange, so HTTP_PORT_COUNT - 1 supplies exactly the two reserved candidates. The worker reads its bound connector port instead of assuming the base.
  • All original test methods, exact HTTP status/body assertions, two-member cluster assertions, checkpoint restore identity/mode assertions and wait budgets are unchanged. No CI selection is removed or relaxed.

Runtime chain: fixture allocation -> configuration -> master and worker Hazelcast startup -> each enabled Jetty listener chooses a free port in the reserved two-port range -> getHttpPort(workerServer) locates the actual worker connector -> REST/savepoint tests execute. Normal fixture startup reaches the change. Hazelcast auto-increment and discovery remain at 100 ports. Exception handling, checkpoint setup and teardown are unchanged. Allocator reservations are JVM bookkeeping rather than held OS sockets, so unrelated-process races remain an existing limitation.

Compatibility and quality: only test-fixture configuration changes. Production API/SPI/configuration names/defaults, old job semantics, checkpoint/savepoint serialization, connector registration and resources remain untouched. No migration or user-facing English/Chinese documentation is needed. No new thread/timer/queue/retry/logging or cleanup ownership is added. Existing REST option-rule and checkpoint component/integration tests retain failure capability; ordinary connector E2E is not claimed as proof of this fixture repair.

Change-location assessment: the root cause is fixture-local REST ports bypassing an existing shared allocation contract. These fixture initializers/setup and their small HTTP range are the best change locations. The smallest safe fix and global best fix coincide: use the existing allocator for every candidate port these fixtures may bind. Changing discovery, production JettyService, shared HttpConfig behavior or the allocator itself would expand compatibility and verification costs unnecessarily. The PR is a focused root-cause fixture fix, not a timeout/retry workaround.

Actual verification:

  • git fetch upstream pull/13030/head:codex-review-13030-20261028, exact-ref git show, full git diff cec3276740d989c8cb67c7b8c37e0a817e728059...codex-review-13030-20261028, git diff --check: passed; both complete changed files and affected allocator/configuration/Jetty chains inspected.
  • gh pr view 13030 --json headRefOid,mergeable,mergeStateStatus,reviewDecision,reviews,statusCheckRollup and REST review/comment reads: passed; no prior formal or inline review/comments were present at review time.
  • Compilation, unit tests, integration tests, E2E, Docker and services: not run, under the repository's CI-only runtime-validation rule. No artifacts were reused, and seatunnel-engine-ui was not built because no build ran. Contributor-reported checks are not independent runtime evidence.

Completeness cross-check: all changed lines and deletions, initialization order, shared-configuration boundary, inclusive range arithmetic, actual bound-port lookup, preserved assertions, failure/cleanup paths, configuration compatibility, documentation applicability and current gates were examined. No changed file remains unreviewed. No evidenced introduced blocking or nonblocking source defect was found.

Merge gates at review time: MERGEABLE, mergeStateStatus=BLOCKED, reviewDecision=REVIEW_REQUIRED; PR signal succeeded, while Build is queued. Relevant current-head unit-test matrix execution and independent human approval remain outstanding. Conclusion: source review has no blocking findings; do not merge until those gates pass. This COMMENT does not grant approval.

Publication gate snapshot (2026-10-28 02:44:47 EDT (UTC-0400)): reviewed head 7bd50c98251346b2635880b70953cc5483fef033 remains current; mergeable=MERGEABLE, mergeStateStatus=BLOCKED, reviewDecision=REVIEW_REQUIRED. Exact-head checks: Signal pull request update COMPLETED/SUCCESS; Build IN_PROGRESS. This latest snapshot supersedes earlier gate observations above; it does not replace required runtime coverage or approval.

@DanielLeens

Copy link
Copy Markdown
Contributor Author

Thanks for the contribution. The CI fact cited in my previous conclusion has changed; this follow-up updates that gate on the unchanged reviewed head, without issuing another full source review.

Gate snapshot (2026-10-28T15:52:20+00:00), head 7bd50c98251346b2635880b70953cc5483fef033: Build is FAILURE.

The blocking jobs are Run / engine-v2-it (17, ubuntu-latest) failure; Run / jdbc-connectors-it-part-7 (11, ubuntu-latest) failure.

Observed log evidence: Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.10.3:install-node-and-npm (install node and npm) on project seatunnel-engine-ui: Could not extract the Node archive: Could not extract archive: '/home/runner/.m2/repository/com/github/eirslett/node/16.13.2/node-16.13.2-linux-x64.tar.gz': EOFException -> [Help 1]

This evidence points to artifact transfer/extraction rather than establishing a product-diff defect. Rerun only the affected failed job after the transient artifact/cache problem is corrected. A simple base sync does not repair a connection reset or corrupted runner archive; I found no verified source-sync cure for that exact environment failure.

My previous source conclusion remains clear for the reviewed scope. CI is not being passed by inference, and this follow-up is not an effective approval.

Comparison recorded in this scan: base dev, diverged, ahead 1 / behind 7, no merge conflict. Branch drift is metadata here and is not an additional sync request.

@davidzollo davidzollo left a comment

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.

+1 if CI passes.
LGTM, thanks for your work and keep up the good effort!

@DanielLeens DanielLeens left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the update. I re-read the complete changed-head diff and checked the affected fixture lifecycle.

What Problem Does This PR Solve?

User pain point: Two REST fixtures bypass the shared port allocator and can collide with other tests in the same JVM.

Fix approach: Allocate the option-rule HTTP port and the savepoint fixture's two HTTP candidates through TestUtils.getAvailablePort.

One-sentence summary and example: The two-member fixture reserves ports p and p+1 and sets Jetty's inclusive range to 1 instead of scanning a 2000-port range outside its reservation.

1. Code Change Review

1.1 Core Logic Analysis

OptionRulesApiTest uses one allocated HTTP port with dynamic-port selection disabled. RestApiSubmitJobStartWithSavePointTest reserves two consecutive ports because members can share HttpConfig. JettyService.chooseAppropriatePort uses <= initialPort + portRange, so HTTP_PORT_COUNT - 1 matches the reservation. The worker URL comes from its bound connector, not an assumed base port. The fixed 20000 argument is on the initially HTTP-disabled master setup; shared configuration can later enable both listeners on the reserved range.

Before:

HTTP_PORT = 18082;
createSeaTunnelConfig(clusterName, 23000, true);
httpConfig.setPortRange(2000);

After:

HTTP_PORT = TestUtils.getAvailablePort();
workerHttpPort = TestUtils.getAvailablePort(2);
httpConfig.setPortRange(1);

Key Findings

  • The allocator records inclusive reservations and checks bindability.
  • The configured Jetty range matches exactly two candidates.
  • Existing REST status/body, cluster-membership and savepoint assertions are preserved.

Complete runtime path

Fixture setup -> shared port allocator -> SeaTunnelConfig -> Hazelcast member startup
 -> JettyService chooses available candidate -> bound worker connector -> REST requests
 -> existing teardown closes members and fixture files

The allocation/configuration arithmetic is consistent. Reservations are JVM bookkeeping rather than sockets held until Jetty binds, so an unrelated process can still race; this pre-existing allocator limitation is not introduced by the PR.

1.2 Compatibility Impact

Fully compatible. Test-only change; production APIs, options, dependencies and checkpoint formats are unchanged.

1.3 Performance / Side-Effect Analysis

No production cost. The existing fixture owns the same resources and assertions.

1.4 Error Handling and Logging

Existing startup/assertion exceptions and teardown handling remain unchanged.
No blocking source issues found. No numbered source findings remain for this head.

2. Code Quality Assessment

2.1 Coding Standards

The narrow existing-fixture edit follows the project style and documents its lifecycle constraint.

2.2 Test Coverage and Test Stability

Test stability: Stable for the change. The fix reduces intra-JVM port collisions without adding sleeps, larger timeouts, retries or weakened assertions. Both existing real-server fixtures retain their failure capability and teardown. It is not a claim that external port races become impossible.

Local analysis: fetched the head, created independent branch seatunnel-review-13030, read the complete 2-file diff and traced affected callers with git show/git grep. No local compilation, unit tests, integration tests, E2E, containers, or job execution was performed, as requested. These are source-analysis conclusions; execution evidence is the current-head CI below.

2.3 Documentation Updates

No user-facing English/Chinese guide or migration change is required for this test-only correction.

3. Architectural Soundness

3.1 Elegance of the Solution

Precise fix. The fixtures own the incorrect port choices, so changing them is the smallest safe fix. Production Jetty/discovery behavior does not need alteration.

3.2 Maintainability

Keep the lifecycle invariant documented next to the existing setup/cleanup.

3.3 Extensibility

No new framework or shared production abstraction is needed.

3.4 Historical-Version Compatibility

No production upgrade or state migration is introduced.

4. Issue Summary

Number Issue Location Severity
— No formal issues found Complete changed-file set —

5. Merge Recommendation

Conclusion: Ready to merge

  1. Blockers — must be fixed
    • No source blocker identified. Current-head CI is successful; effective independent maintainer approval and repository gates still apply.
  2. Recommended fixes — non-blocking
    • No additional unrelated changes requested.

Overall assessment: No source blocker found. The exact-head successful CI clears the earlier pending Build observation.

Existing-review reconciliation: @davidzollo expressed LGTM conditional on CI. The current head reports successful checks; the repository's actual required-review gate still applies. Author replies have been incorporated into this single full review.

Head e7d69741a21026aba9801147a4ffabbe72ccb993. Live base dev at 3ac2d1cec6aa7b3741c4dacdd23020f778e23c02; comparison ahead, ahead 2 / behind 0; merge state CLEAN. Behind/diverged alone is recorded metadata, not a request to synchronize upstream. Checks: Label PRs when reviewed = SUCCESS; Signal pull request update = SUCCESS; Build = SUCCESS

The current-head Build and Signal checks are SUCCESS.

Daniel has READ repository permission. This COMMENT records the technical conclusion; it is not an effective maintainer approval or a dismissal of any historical requested-changes entry. A write-capable maintainer owns the final repository approval gate.

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

+1 LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants