nzw921rx opened a new pull request, #11096:
URL: https://github.com/apache/seatunnel/pull/11096

   ## Purpose  of this pull request
   
   Fix flaky E2E tests caused by fixed Docker port bindings in Flink and 
SeaTunnel engine test containers.
   
   ## Problem
   
   The E2E test framework containers (`AbstractTestFlinkContainer`, 
`Flink20Container`, `SeaTunnelContainer`) used **fixed host port bindings** 
(e.g., `8081:8081`, `5801:5801`, `8080:8080`) via `setPortBindings()`.
   
   This caused **"port is already allocated"** errors leading to cascading test 
failures:
   
   ```
   com.github.dockerjava.api.exception.InternalServerErrorException: Status 500:
     {"message":"Bind for 0.0.0.0:8081 failed: port is already allocated"}
   ```
   
   ### Root Cause
   
   When a test container fails (e.g., due to timeout or resource exhaustion) 
and doesn't release the fixed port properly, **all subsequent tests** 
attempting to bind the same port will fail immediately. This is a primary cause 
of flaky tests in CI that pass on re-run.
   
   ### Failure Scenario
   
   1. Test A starts a Flink container bound to host port `8081`
   2. Test A fails/hangs, the container doesn't cleanly release port `8081`
   3. Tests B, C, D... all try to start Flink containers on the same fixed port 
`8081`
   4. All fail with `port is already allocated` — cascading failures
   
   ## Solution
   
   Replace fixed port bindings (`setPortBindings`) with dynamic port allocation 
(`withExposedPorts(port)`). Docker automatically assigns a random available 
host port for each container, eliminating port conflicts.
   
   The test code already uses `getMappedPort(port)` to access containers from 
the host, so this change is fully backward-compatible.
   
   ## Changes
   
   | File | Before | After |
   |------|--------|-------|
   | `AbstractTestFlinkContainer.java` | `.withExposedPorts()` + 
`setPortBindings("8081:8081")` | `.withExposedPorts(8081)` |
   | `Flink20Container.java` | `.withExposedPorts()` + 
`setPortBindings("8081:8081")` | `.withExposedPorts(8081)` |
   | `SeaTunnelContainer.java` (2 places) | `.withExposedPorts()` + 
`setPortBindings("5801:5801", "8080:8080")` | `.withExposedPorts(5801, 8080)` |
   
   ## Impact
   
   - Flink E2E tests (all versions: 1.4, 1.8, 2.0) will no longer conflict on 
port 8081
   - SeaTunnel engine E2E tests will no longer conflict on ports 5801/8080
   - Multiple test containers can coexist on the same CI runner without port 
collisions
   - Significantly reduces flaky test rate in CI


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to