Skip to content

Commit a4e082e

Browse files
committed
8253368: TLS connection always receives close_notify exception
Reviewed-by: xuelei
1 parent 4ea8851 commit a4e082e

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

src/java.base/share/classes/sun/security/ssl/SSLSocketImpl.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -820,16 +820,17 @@ private void shutdownInput(
820820
// Is it ready to close inbound?
821821
//
822822
// No need to throw exception if the initial handshake is not started.
823-
if (checkCloseNotify && !conContext.isInputCloseNotified &&
824-
(conContext.isNegotiated || conContext.handshakeContext != null)) {
825-
826-
throw conContext.fatal(Alert.INTERNAL_ERROR,
823+
try {
824+
if (checkCloseNotify && !conContext.isInputCloseNotified &&
825+
(conContext.isNegotiated || conContext.handshakeContext != null)) {
826+
throw new SSLException(
827827
"closing inbound before receiving peer's close_notify");
828-
}
829-
830-
conContext.closeInbound();
831-
if ((autoClose || !isLayered()) && !super.isInputShutdown()) {
832-
super.shutdownInput();
828+
}
829+
} finally {
830+
conContext.closeInbound();
831+
if ((autoClose || !isLayered()) && !super.isInputShutdown()) {
832+
super.shutdownInput();
833+
}
833834
}
834835
}
835836

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,9 +23,10 @@
2323

2424
/*
2525
* @test
26-
* @bug 8184328
26+
* @bug 8184328 8253368
2727
* @summary JDK8u131-b34-socketRead0 hang at SSL read
2828
* @run main/othervm SSLSocketCloseHang
29+
* @run main/othervm SSLSocketCloseHang shutdownInputTest
2930
*/
3031

3132
import java.io.*;
@@ -72,6 +73,8 @@ public class SSLSocketCloseHang {
7273
*/
7374
static boolean debug = false;
7475

76+
static boolean shutdownInputTest = false;
77+
7578
/*
7679
* If the client or server is doing some kind of object creation
7780
* that the other side depends on, and that thread prematurely
@@ -145,7 +148,26 @@ void doClientSide() throws Exception {
145148
Thread.sleep(500);
146149
System.err.println("Client closing: " + System.nanoTime());
147150

148-
sslSocket.close();
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+
}
164+
165+
} else {
166+
sslSocket.close();
167+
}
168+
169+
170+
149171
clientClosed = true;
150172
System.err.println("Client closed: " + System.nanoTime());
151173
}
@@ -179,6 +201,8 @@ public static void main(String[] args) throws Exception {
179201
if (debug)
180202
System.setProperty("javax.net.debug", "all");
181203

204+
shutdownInputTest = args.length > 0 ? true : false;
205+
182206
/*
183207
* Start the tests.
184208
*/

0 commit comments

Comments
 (0)