Skip to content
Permalink
Browse files
8260923: Add more tests for SSLSocket input/output shutdown
Reviewed-by: coffeys
  • Loading branch information
Abdul Kolarkunnu committed Apr 9, 2021
1 parent 33fa855 commit 9bb1863ed719a2a0108ef514ce59ffc5b4febe21
Showing 1 changed file with 46 additions and 23 deletions.
@@ -23,20 +23,24 @@

/*
* @test
* @bug 8184328 8253368
* @bug 8184328 8253368 8260923
* @summary JDK8u131-b34-socketRead0 hang at SSL read
* @run main/othervm SSLSocketCloseHang
* @run main/othervm SSLSocketCloseHang shutdownInputTest
* @run main/othervm SSLSocketCloseHang TLSv1.2
* @run main/othervm SSLSocketCloseHang TLSv1.2 shutdownInput
* @run main/othervm SSLSocketCloseHang TLSv1.2 shutdownOutput
* @run main/othervm SSLSocketCloseHang TLSv1.3
* @run main/othervm SSLSocketCloseHang TLSv1.3 shutdownInput
* @run main/othervm SSLSocketCloseHang TLSv1.3 shutdownOutput
*/


import java.io.*;
import java.net.*;
import java.util.*;
import java.security.*;
import javax.net.ssl.*;

public class SSLSocketCloseHang {

/*
* =============================================================
* Set the various variables needed for the tests, then
@@ -73,7 +77,7 @@ public class SSLSocketCloseHang {
*/
static boolean debug = false;

static boolean shutdownInputTest = false;
static String socketCloseType;

/*
* If the client or server is doing some kind of object creation
@@ -148,28 +152,45 @@ void doClientSide() throws Exception {
Thread.sleep(500);
System.err.println("Client closing: " + System.nanoTime());

if (shutdownInputTest) {
try {
sslSocket.shutdownInput();
} catch (SSLException e) {
if (!e.getMessage().contains
("closing inbound before receiving peer's close_notify")) {
throw new RuntimeException("expected different exception message. " +
e.getMessage());
}
}
if (!sslSocket.getSession().isValid()) {
throw new RuntimeException("expected session to remain valid");
}
closeConnection(sslSocket);

clientClosed = true;
System.err.println("Client closed: " + System.nanoTime());
}

private void closeConnection(SSLSocket sslSocket) throws IOException {
if ("shutdownInput".equals(socketCloseType)) {
shutdownInput(sslSocket);
// second call to shutdownInput() should just return,
// shouldn't throw any exception
sslSocket.shutdownInput();
// invoking shutdownOutput() just after shutdownInput()
sslSocket.shutdownOutput();
} else if ("shutdownOutput".equals(socketCloseType)) {
sslSocket.shutdownOutput();
// second call to shutdownInput() should just return,
// shouldn't throw any exception
sslSocket.shutdownOutput();
// invoking shutdownInput() just after shutdownOutput()
shutdownInput(sslSocket);
} else {
sslSocket.close();
}
}



clientClosed = true;
System.err.println("Client closed: " + System.nanoTime());
private void shutdownInput(SSLSocket sslSocket) throws IOException {
try {
sslSocket.shutdownInput();
} catch (SSLException e) {
if (!e.getMessage().contains
("closing inbound before receiving peer's close_notify")) {
throw new RuntimeException("expected different exception "
+ "message. " + e.getMessage());
}
}
if (!sslSocket.getSession().isValid()) {
throw new RuntimeException("expected session to remain valid");
}
}

/*
@@ -197,11 +218,13 @@ public static void main(String[] args) throws Exception {
System.setProperty("javax.net.ssl.keyStorePassword", passwd);
System.setProperty("javax.net.ssl.trustStore", trustFilename);
System.setProperty("javax.net.ssl.trustStorePassword", passwd);
System.setProperty("jdk.tls.client.protocols", args[0]);

if (debug)
System.setProperty("javax.net.debug", "all");

shutdownInputTest = args.length > 0 ? true : false;
socketCloseType = args.length > 1 ? args[1] : "";


/*
* Start the tests.

1 comment on commit 9bb1863

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 9bb1863 Apr 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.