Skip to content

Commit

Permalink
KAFKA-2817; Check if socketChannel is connected in `SslTransportLayer…
Browse files Browse the repository at this point in the history
….close`

This avoids spurious log warning messages. Also tweak log message
if wrapResult.getStatus != CLOSED.

Author: Ismael Juma <[email protected]>

Reviewers: Rajini Sivaram <[email protected]>, Jun Rao <[email protected]>

Closes apache#511 from ijuma/kafka-2817-unconnected-ssl-transport-layer-close
  • Loading branch information
ijuma authored and junrao committed Nov 13, 2015
1 parent 4170847 commit 528c78f
Showing 1 changed file with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,22 @@ public void close() {
closing = true;
sslEngine.closeOutbound();
try {
if (!flush(netWriteBuffer)) {
throw new IOException("Remaining data in the network buffer, can't send SSL close message.");
}
//prep the buffer for the close message
netWriteBuffer.clear();
//perform the close, since we called sslEngine.closeOutbound
SSLEngineResult handshake = sslEngine.wrap(emptyBuf, netWriteBuffer);
//we should be in a close state
if (handshake.getStatus() != SSLEngineResult.Status.CLOSED) {
throw new IOException("Invalid close state, will not send network data.");
if (isConnected()) {
if (!flush(netWriteBuffer)) {
throw new IOException("Remaining data in the network buffer, can't send SSL close message.");
}
//prep the buffer for the close message
netWriteBuffer.clear();
//perform the close, since we called sslEngine.closeOutbound
SSLEngineResult wrapResult = sslEngine.wrap(emptyBuf, netWriteBuffer);
//we should be in a close state
if (wrapResult.getStatus() != SSLEngineResult.Status.CLOSED) {
throw new IOException("Unexpected status returned by SSLEngine.wrap, expected CLOSED, received " +
wrapResult.getStatus() + ". Will not send close message to peer.");
}
netWriteBuffer.flip();
flush(netWriteBuffer);
}
netWriteBuffer.flip();
flush(netWriteBuffer);
} catch (IOException ie) {
log.warn("Failed to send SSL Close message ", ie);
} finally {
Expand Down

0 comments on commit 528c78f

Please sign in to comment.