Skip to content

Commit 408e0a9

Browse files
Evan Whelanseanjmullan
Evan Whelan
authored andcommitted
8255148: Confusing log output: SSLSocket duplex close failed
Reviewed-by: mullan
1 parent bbd0313 commit 408e0a9

File tree

2 files changed

+106
-4
lines changed

2 files changed

+106
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ public void close() throws IOException {
587587
} catch (IOException ioe) {
588588
// ignore the exception
589589
if (SSLLogger.isOn && SSLLogger.isOn("ssl")) {
590-
SSLLogger.warning("SSLSocket duplex close failed", ioe);
590+
SSLLogger.warning("SSLSocket duplex close failed. Debug info only. Exception details:", ioe);
591591
}
592592
} finally {
593593
if (!isClosed()) {
@@ -597,7 +597,7 @@ public void close() throws IOException {
597597
} catch (IOException ioe) {
598598
// ignore the exception
599599
if (SSLLogger.isOn && SSLLogger.isOn("ssl")) {
600-
SSLLogger.warning("SSLSocket close failed", ioe);
600+
SSLLogger.warning("SSLSocket close failed. Debug info only. Exception details:", ioe);
601601
}
602602
} finally {
603603
tlsIsClosed = true;
@@ -1134,7 +1134,7 @@ public void close() throws IOException {
11341134
} catch (IOException ioe) {
11351135
// ignore the exception
11361136
if (SSLLogger.isOn && SSLLogger.isOn("ssl")) {
1137-
SSLLogger.warning("input stream close failed", ioe);
1137+
SSLLogger.warning("input stream close failed. Debug info only. Exception details:", ioe);
11381138
}
11391139
}
11401140
}
@@ -1329,7 +1329,7 @@ public void close() throws IOException {
13291329
} catch (IOException ioe) {
13301330
// ignore the exception
13311331
if (SSLLogger.isOn && SSLLogger.isOn("ssl")) {
1332-
SSLLogger.warning("output stream close failed", ioe);
1332+
SSLLogger.warning("output stream close failed. Debug info only. Exception details:", ioe);
13331333
}
13341334
}
13351335
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/**
25+
* @test
26+
* @bug 8255148
27+
* @library /test/lib /javax/net/ssl/templates ../../
28+
* @summary Checks for clarified exception messages for non-fatal SSLSocketImpl exceptions which
29+
* can be ignored by the user
30+
* @run main IgnorableExceptionMessages
31+
*/
32+
33+
/*
34+
* This test runs in another process so we can monitor the debug
35+
* results. The OutputAnalyzer must see correct debug output to return a
36+
* success.
37+
*/
38+
39+
import jdk.test.lib.process.OutputAnalyzer;
40+
import jdk.test.lib.process.ProcessTools;
41+
42+
import javax.net.ssl.SSLHandshakeException;
43+
import java.io.BufferedReader;
44+
import java.io.InputStreamReader;
45+
import java.net.URL;
46+
import java.util.List;
47+
48+
public class IgnorableExceptionMessages extends SSLSocketTemplate {
49+
public static void main(String[] args) throws Exception {
50+
if (args.length > 0) {
51+
// A non-empty set of arguments occurs when the "runTest" argument
52+
// is passed to the test via ProcessTools::executeTestJvm.
53+
//
54+
// This is done because an OutputAnalyzer is unable to read
55+
// the output of the current running JVM, and must therefore create
56+
// a test JVM. When this case occurs, it will inherit all specified
57+
// properties passed to the test JVM - debug flags, tls version, etc.
58+
new IgnorableExceptionMessages().run();
59+
} else {
60+
String clientTLSVersion = "-Djdk.tls.client.protocols=TLSv1.2";
61+
String javaxDebugFlag = "-Djavax.net.debug=all";
62+
String className = "IgnorableExceptionMessages";
63+
String extraArgument = "runTest"; // Triggers the test JVM to execute when args.length > 0
64+
List<String> jvmArgs = List.of(
65+
clientTLSVersion,
66+
javaxDebugFlag,
67+
className,
68+
extraArgument);
69+
70+
OutputAnalyzer output = ProcessTools.executeTestJvm(jvmArgs);
71+
72+
if (output.getExitValue() != 0) {
73+
output.asLines().forEach(System.out::println); // No need to dump the output unless the test fails
74+
throw new RuntimeException("Test JVM process failed");
75+
}
76+
77+
try {
78+
output.shouldContain("SSLSocket duplex close failed. Debug info only. Exception details:");
79+
} catch (Exception ex) {
80+
output.asLines().forEach(System.out::println); // No need to dump the output unless the test fails
81+
throw ex;
82+
}
83+
}
84+
}
85+
86+
@Override
87+
protected void runClientApplication(int serverPort) throws Exception {
88+
String urlString = "https://localhost:" + serverPort + "/";
89+
URL url = new URL(urlString);
90+
91+
try {
92+
new BufferedReader(new InputStreamReader(url.openStream()));
93+
for(int i = 0; i < 10; i++) {
94+
Thread.sleep(1000);
95+
System.gc();
96+
}
97+
} catch (SSLHandshakeException sslEx) {
98+
System.out.println(sslEx.getCause());
99+
System.out.println(sslEx.getMessage());
100+
}
101+
}
102+
}

0 commit comments

Comments
 (0)