Skip to content

Commit

Permalink
KAFKA-2779; Close SSL socket channel on remote connection close
Browse files Browse the repository at this point in the history
Close socket channel in finally block to avoid file descriptor leak when remote end closes the connection

Author: Rajini Sivaram <[email protected]>

Reviewers: Ismael Juma <[email protected]>, Jun Rao <[email protected]>

Closes apache#460 from rajinisivaram/KAFKA-2779
  • Loading branch information
rajinisivaram authored and junrao committed Nov 9, 2015
1 parent f2031d4 commit efbebc6
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,9 @@ public boolean isConnected() {

/**
* Sends a SSL close message and closes socketChannel.
* @throws IOException if an I/O error occurs
* @throws IOException if there is data on the outgoing network buffer and we are unable to flush it
*/
@Override
public void close() throws IOException {
public void close() {
if (closing) return;
closing = true;
sslEngine.closeOutbound();
Expand All @@ -159,10 +157,15 @@ public void close() throws IOException {
}
netWriteBuffer.flip();
flush(netWriteBuffer);
socketChannel.socket().close();
socketChannel.close();
} catch (IOException ie) {
log.warn("Failed to send SSL Close message ", ie);
} finally {
try {
socketChannel.socket().close();
socketChannel.close();
} catch (IOException e) {
log.warn("Failed to close SSL socket channel: " + e);
}
}
key.attach(null);
key.cancel();
Expand Down

0 comments on commit efbebc6

Please sign in to comment.