8216326: SSLSocket stream close() does not close the associated socket
authorxuelei
Tue, 16 Apr 2019 16:59:09 -0700
changeset 54551 6f8a7671afef
parent 54550 5fa7fbddfe9d
child 54558 15f2aae40bc8
8216326: SSLSocket stream close() does not close the associated socket Reviewed-by: jnimeh
src/java.base/share/classes/sun/security/ssl/SSLSocketImpl.java
test/jdk/javax/net/ssl/SSLSocket/InputStreamClosure.java
test/jdk/javax/net/ssl/SSLSocket/OutputStreamClosure.java
--- a/src/java.base/share/classes/sun/security/ssl/SSLSocketImpl.java	Wed Apr 17 00:06:38 2019 +0200
+++ b/src/java.base/share/classes/sun/security/ssl/SSLSocketImpl.java	Tue Apr 16 16:59:09 2019 -0700
@@ -980,7 +980,7 @@
             }
 
             try {
-                shutdownInput(false);
+                SSLSocketImpl.this.close();
             } catch (IOException ioe) {
                 // ignore the exception
                 if (SSLLogger.isOn && SSLLogger.isOn("ssl")) {
@@ -1146,7 +1146,7 @@
             }
 
             try {
-                shutdownOutput();
+                SSLSocketImpl.this.close();
             } catch (IOException ioe) {
                 // ignore the exception
                 if (SSLLogger.isOn && SSLLogger.isOn("ssl")) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javax/net/ssl/SSLSocket/InputStreamClosure.java	Tue Apr 16 16:59:09 2019 -0700
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+//
+// Please run in othervm mode.  SunJSSE does not support dynamic system
+// properties, no way to re-use system properties in samevm/agentvm mode.
+//
+
+/*
+ * @test
+ * @bug 8216326
+ * @modules jdk.crypto.ec
+ * @library /javax/net/ssl/templates
+ * @summary SSLSocket stream close() does not close the associated socket
+ * @run main/othervm InputStreamClosure
+ */
+import java.io.InputStream;
+import java.io.OutputStream;
+import javax.net.ssl.SSLSocket;
+
+public class InputStreamClosure extends SSLSocketTemplate {
+
+    // Run the test case.
+    public static void main(String[] args) throws Exception {
+        (new InputStreamClosure()).run();
+    }
+
+    @Override
+    protected void runServerApplication(SSLSocket socket) throws Exception {
+        // here comes the test logic
+        InputStream sslIS = socket.getInputStream();
+        OutputStream sslOS = socket.getOutputStream();
+
+        sslIS.read();
+        sslOS.write(85);
+        sslOS.flush();
+    }
+
+    /*
+     * Define the client side application of the test for the specified socket.
+     * This method is used if the returned value of
+     * isCustomizedClientConnection() is false.
+     *
+     * @param socket may be null is no client socket is generated.
+     *
+     * @see #isCustomizedClientConnection()
+     */
+    protected void runClientApplication(SSLSocket socket) throws Exception {
+        InputStream sslIS = socket.getInputStream();
+        OutputStream sslOS = socket.getOutputStream();
+
+        sslOS.write(280);
+        sslOS.flush();
+        sslIS.read();
+
+        sslIS.close();
+        if (!socket.isClosed()) {
+            throw new Exception("Closing the SSLSocket InputStream does " +
+                    "not close the associated socket");
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javax/net/ssl/SSLSocket/OutputStreamClosure.java	Tue Apr 16 16:59:09 2019 -0700
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+//
+// Please run in othervm mode.  SunJSSE does not support dynamic system
+// properties, no way to re-use system properties in samevm/agentvm mode.
+//
+
+/*
+ * @test
+ * @bug 8216326
+ * @modules jdk.crypto.ec
+ * @library /javax/net/ssl/templates
+ * @summary SSLSocket stream close() does not close the associated socket
+ * @run main/othervm OutputStreamClosure
+ */
+import java.io.InputStream;
+import java.io.OutputStream;
+import javax.net.ssl.SSLSocket;
+
+public class OutputStreamClosure extends SSLSocketTemplate {
+
+    // Run the test case.
+    public static void main(String[] args) throws Exception {
+        (new OutputStreamClosure()).run();
+    }
+
+    @Override
+    protected void runServerApplication(SSLSocket socket) throws Exception {
+        // here comes the test logic
+        InputStream sslIS = socket.getInputStream();
+        OutputStream sslOS = socket.getOutputStream();
+
+        sslIS.read();
+        sslOS.write(85);
+        sslOS.flush();
+    }
+
+    /*
+     * Define the client side application of the test for the specified socket.
+     * This method is used if the returned value of
+     * isCustomizedClientConnection() is false.
+     *
+     * @param socket may be null is no client socket is generated.
+     *
+     * @see #isCustomizedClientConnection()
+     */
+    protected void runClientApplication(SSLSocket socket) throws Exception {
+        InputStream sslIS = socket.getInputStream();
+        OutputStream sslOS = socket.getOutputStream();
+
+        sslOS.write(280);
+        sslOS.flush();
+        sslIS.read();
+
+        sslOS.close();
+        if (!socket.isClosed()) {
+            throw new Exception("Closing the SSLSocket OutputStream does " +
+                    "not close the associated socket");
+        }
+    }
+}