kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jun...@apache.org
Subject kafka git commit: KAFKA-2817; Check if socketChannel is connected in `SslTransportLayer.close`
Date Fri, 13 Nov 2015 16:29:40 GMT
Repository: kafka
Updated Branches:
  refs/heads/0.9.0 b06ef94e2 -> cb0de177c


KAFKA-2817; Check if socketChannel is connected in `SslTransportLayer.close`

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

Author: Ismael Juma <ismael@juma.me.uk>

Reviewers: Rajini Sivaram <rajinisivaram@googlemail.com>, Jun Rao <junrao@gmail.com>

Closes #511 from ijuma/kafka-2817-unconnected-ssl-transport-layer-close

(cherry picked from commit 528c78fd30b77e8c60e8b3645e7d44404fd4e013)
Signed-off-by: Jun Rao <junrao@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/cb0de177
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/cb0de177
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/cb0de177

Branch: refs/heads/0.9.0
Commit: cb0de177cdc03b63ad1927aba1be292ef5637b68
Parents: b06ef94
Author: Ismael Juma <ismael@juma.me.uk>
Authored: Fri Nov 13 08:29:28 2015 -0800
Committer: Jun Rao <junrao@gmail.com>
Committed: Fri Nov 13 08:29:36 2015 -0800

----------------------------------------------------------------------
 .../kafka/common/network/SslTransportLayer.java | 27 +++++++++++---------
 1 file changed, 15 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/cb0de177/clients/src/main/java/org/apache/kafka/common/network/SslTransportLayer.java
----------------------------------------------------------------------
diff --git a/clients/src/main/java/org/apache/kafka/common/network/SslTransportLayer.java
b/clients/src/main/java/org/apache/kafka/common/network/SslTransportLayer.java
index c7873ad..27e2ea9 100644
--- a/clients/src/main/java/org/apache/kafka/common/network/SslTransportLayer.java
+++ b/clients/src/main/java/org/apache/kafka/common/network/SslTransportLayer.java
@@ -144,19 +144,22 @@ public class SslTransportLayer implements TransportLayer {
         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 {


Mime
View raw message