From 5bfba1decaf3c11bbd7563c8993d7f68739bedb5 Mon Sep 17 00:00:00 2001 From: Rajini Sivaram Date: Wed, 11 May 2016 13:05:58 +0100 Subject: [PATCH] MINOR: Ensure that selection key is cancelled on close Author: Rajini Sivaram Reviewers: Ismael Juma Closes #1368 from rajinisivaram/minor-channelclose (cherry picked from commit e20eba958d8de29cb4e3b6feea37ac3a1e1ab4f9) Signed-off-by: Ismael Juma --- .../common/network/PlaintextTransportLayer.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/clients/src/main/java/org/apache/kafka/common/network/PlaintextTransportLayer.java b/clients/src/main/java/org/apache/kafka/common/network/PlaintextTransportLayer.java index 3db4345c14f01..1135359f8d196 100644 --- a/clients/src/main/java/org/apache/kafka/common/network/PlaintextTransportLayer.java +++ b/clients/src/main/java/org/apache/kafka/common/network/PlaintextTransportLayer.java @@ -30,11 +30,8 @@ import java.security.Principal; import org.apache.kafka.common.security.auth.KafkaPrincipal; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class PlaintextTransportLayer implements TransportLayer { - private static final Logger log = LoggerFactory.getLogger(PlaintextTransportLayer.class); private final SelectionKey key; private final SocketChannel socketChannel; private final Principal principal = KafkaPrincipal.ANONYMOUS; @@ -84,10 +81,13 @@ public boolean isConnected() { */ @Override public void close() throws IOException { - socketChannel.socket().close(); - socketChannel.close(); - key.attach(null); - key.cancel(); + try { + socketChannel.socket().close(); + socketChannel.close(); + } finally { + key.attach(null); + key.cancel(); + } } /**