Aiven-Open / Aiven-Open/kafka-testkit

Stabilize Kafka test startup by removing race-prone ephemeral port discovery in KafkaConnectRunner

Open
#6 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

# What happened?

In `KafkaConnectRunner`, `findListenerPorts()` discovers candidate ports by opening `ServerSocket(0)`, reading assigned ports, and then closing the sockets before Kafka binds.

This creates a race window: another process/test can claim one or more of those ports before Kafka starts. The recent change increases this from 2 to 3 ports (listeners + KRaft controller), which increases the probability of test flakiness under parallel or busy environments.

Observed risk:
- Intermittent startup failures due to bind conflicts on previously “found” ports.
- Non-deterministic CI/test behavior, especially with concurrent test execution.

# What did you expect to happen?

Port selection should be race-safe enough to improve startup stability rather than introduce/expand flake potential.

Expected behavior:
- Either reserve ports until Kafka is configured/bound, or
- Let Kafka/EmbeddedConnectCluster bind to port 0 directly and read back the effective assigned ports after startup.

This should eliminate the gap between port discovery and actual bind, reducing intermittent bind failures.

# What else do we need to know?

- Note: The Javadoc already states ports are not reserved, but current behavior still conflicts with the stabilization goal.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.