Skip to content

Commit 9bb1863

Browse files
author
Abdul Kolarkunnu
committed
8260923: Add more tests for SSLSocket input/output shutdown
Reviewed-by: coffeys
1 parent 33fa855 commit 9bb1863

File tree

1 file changed

+46
-23
lines changed

1 file changed

+46
-23
lines changed

test/jdk/sun/security/ssl/SSLSocketImpl/SSLSocketCloseHang.java

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,24 @@
2323

2424
/*
2525
* @test
26-
* @bug 8184328 8253368
26+
* @bug 8184328 8253368 8260923
2727
* @summary JDK8u131-b34-socketRead0 hang at SSL read
28-
* @run main/othervm SSLSocketCloseHang
29-
* @run main/othervm SSLSocketCloseHang shutdownInputTest
28+
* @run main/othervm SSLSocketCloseHang TLSv1.2
29+
* @run main/othervm SSLSocketCloseHang TLSv1.2 shutdownInput
30+
* @run main/othervm SSLSocketCloseHang TLSv1.2 shutdownOutput
31+
* @run main/othervm SSLSocketCloseHang TLSv1.3
32+
* @run main/othervm SSLSocketCloseHang TLSv1.3 shutdownInput
33+
* @run main/othervm SSLSocketCloseHang TLSv1.3 shutdownOutput
3034
*/
3135

36+
3237
import java.io.*;
3338
import java.net.*;
3439
import java.util.*;
3540
import java.security.*;
3641
import javax.net.ssl.*;
3742

3843
public class SSLSocketCloseHang {
39-
4044
/*
4145
* =============================================================
4246
* Set the various variables needed for the tests, then
@@ -73,7 +77,7 @@ public class SSLSocketCloseHang {
7377
*/
7478
static boolean debug = false;
7579

76-
static boolean shutdownInputTest = false;
80+
static String socketCloseType;
7781

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

151-
if (shutdownInputTest) {
152-
try {
153-
sslSocket.shutdownInput();
154-
} catch (SSLException e) {
155-
if (!e.getMessage().contains
156-
("closing inbound before receiving peer's close_notify")) {
157-
throw new RuntimeException("expected different exception message. " +
158-
e.getMessage());
159-
}
160-
}
161-
if (!sslSocket.getSession().isValid()) {
162-
throw new RuntimeException("expected session to remain valid");
163-
}
155+
closeConnection(sslSocket);
156+
157+
clientClosed = true;
158+
System.err.println("Client closed: " + System.nanoTime());
159+
}
164160

161+
private void closeConnection(SSLSocket sslSocket) throws IOException {
162+
if ("shutdownInput".equals(socketCloseType)) {
163+
shutdownInput(sslSocket);
164+
// second call to shutdownInput() should just return,
165+
// shouldn't throw any exception
166+
sslSocket.shutdownInput();
167+
// invoking shutdownOutput() just after shutdownInput()
168+
sslSocket.shutdownOutput();
169+
} else if ("shutdownOutput".equals(socketCloseType)) {
170+
sslSocket.shutdownOutput();
171+
// second call to shutdownInput() should just return,
172+
// shouldn't throw any exception
173+
sslSocket.shutdownOutput();
174+
// invoking shutdownInput() just after shutdownOutput()
175+
shutdownInput(sslSocket);
165176
} else {
166177
sslSocket.close();
167178
}
179+
}
168180

169-
170-
171-
clientClosed = true;
172-
System.err.println("Client closed: " + System.nanoTime());
181+
private void shutdownInput(SSLSocket sslSocket) throws IOException {
182+
try {
183+
sslSocket.shutdownInput();
184+
} catch (SSLException e) {
185+
if (!e.getMessage().contains
186+
("closing inbound before receiving peer's close_notify")) {
187+
throw new RuntimeException("expected different exception "
188+
+ "message. " + e.getMessage());
189+
}
190+
}
191+
if (!sslSocket.getSession().isValid()) {
192+
throw new RuntimeException("expected session to remain valid");
193+
}
173194
}
174195

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

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

204-
shutdownInputTest = args.length > 0 ? true : false;
226+
socketCloseType = args.length > 1 ? args[1] : "";
227+
205228

206229
/*
207230
* Start the tests.

0 commit comments

Comments
 (0)