Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 306ff45

Browse files
author
Yuri Nesterenko
committed
8253368: TLS connection always receives close_notify exception
Backport-of: a4e082e9857d6acd126fb0734583b4a1e211f9f7
1 parent 4c7fd83 commit 306ff45

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
@@ -816,16 +816,17 @@ private void shutdownInput(
816816
// Is it ready to close inbound?
817817
//
818818
// No need to throw exception if the initial handshake is not started.
819-
if (checkCloseNotify && !conContext.isInputCloseNotified &&
820-
(conContext.isNegotiated || conContext.handshakeContext != null)) {
821-
822-
throw conContext.fatal(Alert.INTERNAL_ERROR,
819+
try {
820+
if (checkCloseNotify && !conContext.isInputCloseNotified &&
821+
(conContext.isNegotiated || conContext.handshakeContext != null)) {
822+
throw new SSLException(
823823
"closing inbound before receiving peer's close_notify");
824-
}
825-
826-
conContext.closeInbound();
827-
if ((autoClose || !isLayered()) && !super.isInputShutdown()) {
828-
super.shutdownInput();
824+
}
825+
} finally {
826+
conContext.closeInbound();
827+
if ((autoClose || !isLayered()) && !super.isInputShutdown()) {
828+
super.shutdownInput();
829+
}
829830
}
830831
}
831832

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)