[
https://issues.apache.org/jira/browse/KAFKA-7453?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16632509#comment-16632509
]
ASF GitHub Bot commented on KAFKA-7453:
---------------------------------------
rajinisivaram closed pull request #5712: KAFKA-7453: Expire registered channels
not selected within idle timeout
URL: https://github.com/apache/kafka/pull/5712
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/clients/src/main/java/org/apache/kafka/common/network/Selector.java
b/clients/src/main/java/org/apache/kafka/common/network/Selector.java
index 44223e7ab31..93325d5b4a9 100644
--- a/clients/src/main/java/org/apache/kafka/common/network/Selector.java
+++ b/clients/src/main/java/org/apache/kafka/common/network/Selector.java
@@ -319,6 +319,8 @@ private SelectionKey registerChannel(String id,
SocketChannel socketChannel, int
SelectionKey key = socketChannel.register(nioSelector, interestedOps);
KafkaChannel channel = buildAndAttachKafkaChannel(socketChannel, id,
key);
this.channels.put(id, channel);
+ if (idleExpiryManager != null)
+ idleExpiryManager.update(channel.id(), time.nanoseconds());
return key;
}
diff --git
a/clients/src/test/java/org/apache/kafka/common/network/SelectorTest.java
b/clients/src/test/java/org/apache/kafka/common/network/SelectorTest.java
index cfd7fb3af8d..cef7c7fae49 100644
--- a/clients/src/test/java/org/apache/kafka/common/network/SelectorTest.java
+++ b/clients/src/test/java/org/apache/kafka/common/network/SelectorTest.java
@@ -363,6 +363,19 @@ public void testCloseOldestConnection() throws Exception {
assertEquals(ChannelState.EXPIRED, selector.disconnected().get(id));
}
+ @Test
+ public void testIdleExpiryWithoutReadyKeys() throws IOException {
+ String id = "0";
+ selector.connect(id, new InetSocketAddress("localhost", server.port),
BUFFER_SIZE, BUFFER_SIZE);
+ KafkaChannel channel = selector.channel(id);
+ channel.selectionKey().interestOps(0);
+
+ time.sleep(6000); // The max idle time is 5000ms
+ selector.poll(0);
+ assertTrue("The idle connection should have been closed",
selector.disconnected().containsKey(id));
+ assertEquals(ChannelState.EXPIRED, selector.disconnected().get(id));
+ }
+
@Test
public void testImmediatelyConnectedCleaned() throws Exception {
Metrics metrics = new Metrics(); // new metrics object to avoid metric
registration conflicts
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Enable idle expiry of connections which are never selected
> ----------------------------------------------------------
>
> Key: KAFKA-7453
> URL: https://issues.apache.org/jira/browse/KAFKA-7453
> Project: Kafka
> Issue Type: Bug
> Components: network
> Affects Versions: 0.10.2.2, 0.11.0.3, 1.0.2, 1.1.1, 2.0.0
> Reporter: Rajini Sivaram
> Assignee: Rajini Sivaram
> Priority: Major
> Fix For: 2.1.0
>
>
> We add connections to Selector#channels when a connection is registered, but
> we start idle expiry of connections only when the connection is first
> selected. In some environments where the channel may never get selected, this
> could leak memory and sockets.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)