This is an automated email from the ASF dual-hosted git repository.

mblow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git

commit 0dbb0c2c39639262068bdaa8bb6d571fadb3f1da
Author: Murtadha Hubail <[email protected]>
AuthorDate: Thu Feb 4 19:58:47 2021 +0300

    [NO ISSUE][NET] Ensure ssl socket is connected before write
    
    - user model changes: no
    - storage format changes: no
    - interface changes: no
    
    Details:
    
    - Ensure the SSL socket is connected before attempting a
      write/wrap operation.
    - Only attempt to send goodbye message to replicas when
      the socket channel is still connected.
    - Always attempt to close the ssl socket channel even when
      the close handshake fails.
    
    Change-Id: I07fbcd76be29853c94cb133485d83034ceee9cb3
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/9825
    Integration-Tests: Jenkins <[email protected]>
    Reviewed-by: Michael Blow <[email protected]>
    Tested-by: Jenkins <[email protected]>
---
 .../org/apache/asterix/replication/api/PartitionReplica.java  |  4 ++--
 .../java/org/apache/hyracks/ipc/sockets/SslSocketChannel.java | 11 +++++++++--
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git 
a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/api/PartitionReplica.java
 
b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/api/PartitionReplica.java
index 3226299..6b97306 100644
--- 
a/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/api/PartitionReplica.java
+++ 
b/asterixdb/asterix-replication/src/main/java/org/apache/asterix/replication/api/PartitionReplica.java
@@ -113,10 +113,10 @@ public class PartitionReplica implements 
IPartitionReplica {
 
     public synchronized void close() {
         try {
-            if (sc != null) {
+            if (NetworkingUtil.isHealthy(sc)) {
                 sendGoodBye();
-                NetworkUtil.closeQuietly(sc);
             }
+            NetworkUtil.closeQuietly(sc);
         } finally {
             sc = null;
         }
diff --git 
a/hyracks-fullstack/hyracks/hyracks-ipc/src/main/java/org/apache/hyracks/ipc/sockets/SslSocketChannel.java
 
b/hyracks-fullstack/hyracks/hyracks-ipc/src/main/java/org/apache/hyracks/ipc/sockets/SslSocketChannel.java
index 02a1a02..74deefe 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-ipc/src/main/java/org/apache/hyracks/ipc/sockets/SslSocketChannel.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-ipc/src/main/java/org/apache/hyracks/ipc/sockets/SslSocketChannel.java
@@ -20,6 +20,7 @@ package org.apache.hyracks.ipc.sockets;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
+import java.nio.channels.ClosedChannelException;
 import java.nio.channels.SocketChannel;
 
 import javax.net.ssl.SSLEngine;
@@ -142,6 +143,9 @@ public class SslSocketChannel implements ISocketChannel {
         while (src.hasRemaining()) {
             // chunk src to encrypted ssl records of pocket size
             outEncryptedData.clear();
+            if (!socketChannel.isConnected()) {
+                throw new ClosedChannelException();
+            }
             final SSLEngineResult result = engine.wrap(src, outEncryptedData);
             switch (result.getStatus()) {
                 case OK:
@@ -186,8 +190,11 @@ public class SslSocketChannel implements ISocketChannel {
     public synchronized void close() throws IOException {
         if (socketChannel.isOpen()) {
             engine.closeOutbound();
-            new SslHandshake(this).handshake();
-            socketChannel.close();
+            try {
+                new SslHandshake(this).handshake();
+            } finally {
+                socketChannel.close();
+            }
         }
     }
 

Reply via email to