Skip to content

Commit

Permalink
KAFKA-16765: Close leaked accepted sockets in EchoServer, NioEchoServ…
Browse files Browse the repository at this point in the history
…er, ServerShutdownTest (apache#16576)

Reviewers: Greg Harris <[email protected]>
  • Loading branch information
zzzk1 authored Jul 24, 2024
1 parent ee68f32 commit a38829e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public void run() {
}
synchronized (sockets) {
if (closing) {
socket.close();
break;
}
sockets.add(socket);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,20 @@ public void closeSocketChannels() throws IOException {
socketChannels.clear();
}

public void closeNewChannels() throws IOException {
for (SocketChannel channel : newChannels) {
channel.close();
}
newChannels.clear();
}

public void close() throws IOException, InterruptedException {
this.serverSocketChannel.close();
closeSocketChannels();
Utils.closeQuietly(selector, "selector");
acceptorThread.interrupt();
acceptorThread.join();
closeNewChannels();
interrupt();
join();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ class ServerShutdownTest extends KafkaServerTestHarness {
val receiveFuture = executor.submit(new Runnable {
override def run(): Unit = {
val socket = serverSocket.accept()
new DataInputStream(socket.getInputStream).readByte()
val inputStream = new DataInputStream(socket.getInputStream)
inputStream.readByte()
inputStream.close()
}
})

Expand Down

0 comments on commit a38829e

Please sign in to comment.