Skip to content
Permalink
Browse files
[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 <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Michael Blow <mblow@apache.org>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
  • Loading branch information
mhubail committed Feb 5, 2021
1 parent 9f19cef commit 0dbb0c2c39639262068bdaa8bb6d571fadb3f1da
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
@@ -113,10 +113,10 @@ private void establishReplicaConnection() throws IOException {

public synchronized void close() {
try {
if (sc != null) {
if (NetworkingUtil.isHealthy(sc)) {
sendGoodBye();
NetworkUtil.closeQuietly(sc);
}
NetworkUtil.closeQuietly(sc);
} finally {
sc = null;
}
@@ -20,6 +20,7 @@

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 synchronized int write(ByteBuffer src) throws IOException {
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 synchronized boolean completeWrite() throws IOException {
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();
}
}
}

0 comments on commit 0dbb0c2

Please sign in to comment.