Skip to content

Commit

Permalink
MINOR: Ensure that selection key is cancelled on close
Browse files Browse the repository at this point in the history
Author: Rajini Sivaram <[email protected]>

Reviewers: Ismael Juma <[email protected]>

Closes apache#1368 from rajinisivaram/minor-channelclose
  • Loading branch information
rajinisivaram authored and ijuma committed May 11, 2016
1 parent 3e89d2b commit e20eba9
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}

/**
Expand Down

0 comments on commit e20eba9

Please sign in to comment.