-
Notifications
You must be signed in to change notification settings - Fork 14.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KAFKA-18275: Restarting broker in testing should use the same port #18381
base: trunk
Are you sure you want to change the base?
KAFKA-18275: Restarting broker in testing should use the same port #18381
Conversation
|
||
if (socketChannel != null) { | ||
if (socketChannel.isOpen()) { | ||
return socketChannel; | ||
} | ||
// bind the server socket with same port | ||
socketAddress = new InetSocketAddress(socketAddress.getHostString(), socketChannel.socket().getLocalPort()); | ||
socketChannel = ServerSocketFactory.INSTANCE.openServerSocket( | ||
listenerName, | ||
socketAddress, | ||
listenBacklogSize, | ||
recvBufferSize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR depends #18337
private void useFixedBrokerPort() throws IOException { | ||
// Find a free port and use it in the Kafka broker's listeners config. We can't use port 0 in the listeners | ||
// config to get a random free port because in this test we want to stop the Kafka broker and then bring it | ||
// back up and listening on the same port in order to verify that the Connect cluster can re-connect to Kafka | ||
// and continue functioning normally. If we were to use port 0 here, the Kafka broker would most likely listen | ||
// on a different random free port the second time it is started. Note that we can only use the static port | ||
// because we have a single broker setup in this test. | ||
int listenerPort; | ||
try (ServerSocket s = new ServerSocket(0)) { | ||
listenerPort = s.getLocalPort(); | ||
} | ||
brokerProps.put(SocketServerConfigs.LISTENERS_CONFIG, String.format("EXTERNAL://localhost:%d,CONTROLLER://localhost:0", listenerPort)); | ||
connectBuilder | ||
.numBrokers(1) | ||
.brokerProps(brokerProps); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this to pass the following two tests.
Module | Test | Message | Time |
---|---|---|---|
ConnectWorkerIntegrationTest | testBrokerCoordinator() | org.opentest4j.AssertionFailedError: The Kafka cluster used in this test was not able to start successfully in time. If no recent changes have altered the behavior of Kafka brokers or clients, and this error is not occurring frequently, it is probably the result of the testing machine being temporarily overloaded and can be safely ignored. | 62.84s |
ConnectWorkerIntegrationTest | testRequestTimeouts() | org.opentest4j.AssertionFailedError: The Kafka cluster used in this test was not able to start successfully in time. If no recent changes have altered the behavior of Kafka brokers or clients, and this error is not occurring frequently, it is probably the result of the testing machine being temporarily overloaded and can be safely ignored. | 60.51s |
https://github.com/apache/kafka/actions/runs/12595111592?pr=18381
But I don't really know why, investigating...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, EmbeddedConnect uses EmbeddedKafkaCluster, and EmbeddedKafkaCluster uses KafkaClusterTestKit to build cluster, and since the brokers has assigned fixed ports in KafkaClusterTestKit, there is no need to modify the LISTENERS_CONFIG
for them
useFixedBrokerPort(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
useFixedBrokerPort(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
Enable brokers to restart with the same port in ClusterTest.
Tests
In the newly added test
testBrokerRestart
, if we don't have:to preallocate the ports for brokers, it would failed with following logs and error: