author | xuelei |
Mon, 25 Jun 2018 13:41:39 -0700 | |
changeset 50768 | 68fa3d4026ea |
parent 47216 | 71c04702a3d5 |
child 51407 | 910f7b56592f |
permissions | -rw-r--r-- |
100
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
1 |
/* |
50768 | 2 |
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. |
100
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
4 |
* |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
8 |
* |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
13 |
* accompanied this code). |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
14 |
* |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
18 |
* |
5506 | 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. |
|
100
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
22 |
*/ |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
23 |
|
21676
36165f46628f
8014266: regression test AsyncSSLSocketClose.java time out.
xuelei
parents:
14342
diff
changeset
|
24 |
// |
36165f46628f
8014266: regression test AsyncSSLSocketClose.java time out.
xuelei
parents:
14342
diff
changeset
|
25 |
// SunJSSE does not support dynamic system properties, no way to re-use |
36165f46628f
8014266: regression test AsyncSSLSocketClose.java time out.
xuelei
parents:
14342
diff
changeset
|
26 |
// system properties in samevm/agentvm mode. |
36165f46628f
8014266: regression test AsyncSSLSocketClose.java time out.
xuelei
parents:
14342
diff
changeset
|
27 |
// |
36165f46628f
8014266: regression test AsyncSSLSocketClose.java time out.
xuelei
parents:
14342
diff
changeset
|
28 |
|
100
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
29 |
/* |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
30 |
* @test |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
31 |
* @bug 6447412 |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
32 |
* @summary Issue with socket.close() for ssl sockets when poweroff on |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
33 |
* other system |
10328 | 34 |
* @run main/othervm AsyncSSLSocketClose |
100
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
35 |
*/ |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
36 |
|
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
37 |
import javax.net.ssl.*; |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
38 |
import java.io.*; |
50768 | 39 |
import java.util.concurrent.CountDownLatch; |
40 |
import java.util.concurrent.TimeUnit; |
|
100
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
41 |
|
50768 | 42 |
public class AsyncSSLSocketClose implements Runnable { |
100
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
43 |
SSLSocket socket; |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
44 |
SSLServerSocket ss; |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
45 |
|
50768 | 46 |
// Is the socket ready to close? |
47 |
private final CountDownLatch closeCondition = new CountDownLatch(1); |
|
48 |
||
100
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
49 |
// Where do we find the keystores? |
23052
241885315119
8032473: Restructure JSSE regression test hierarchy in jdk test
xuelei
parents:
21676
diff
changeset
|
50 |
static String pathToStores = "../../../../javax/net/ssl/etc"; |
100
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
51 |
static String keyStoreFile = "keystore"; |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
52 |
static String trustStoreFile = "truststore"; |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
53 |
static String passwd = "passphrase"; |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
54 |
|
50768 | 55 |
public static void main(String[] args) throws Exception { |
100
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
56 |
String keyFilename = |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
57 |
System.getProperty("test.src", "./") + "/" + pathToStores + |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
58 |
"/" + keyStoreFile; |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
59 |
String trustFilename = |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
60 |
System.getProperty("test.src", "./") + "/" + pathToStores + |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
61 |
"/" + trustStoreFile; |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
62 |
|
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
63 |
System.setProperty("javax.net.ssl.keyStore", keyFilename); |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
64 |
System.setProperty("javax.net.ssl.keyStorePassword", passwd); |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
65 |
System.setProperty("javax.net.ssl.trustStore", trustFilename); |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
66 |
System.setProperty("javax.net.ssl.trustStorePassword", passwd); |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
67 |
|
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
68 |
new AsyncSSLSocketClose(); |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
69 |
} |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
70 |
|
50768 | 71 |
public AsyncSSLSocketClose() throws Exception { |
72 |
SSLServerSocketFactory sslssf = |
|
100
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
73 |
(SSLServerSocketFactory)SSLServerSocketFactory.getDefault(); |
50768 | 74 |
ss = (SSLServerSocket) sslssf.createServerSocket(0); |
100
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
75 |
|
50768 | 76 |
SSLSocketFactory sslsf = |
77 |
(SSLSocketFactory)SSLSocketFactory.getDefault(); |
|
78 |
socket = (SSLSocket)sslsf.createSocket("localhost", ss.getLocalPort()); |
|
79 |
SSLSocket serverSoc = (SSLSocket)ss.accept(); |
|
80 |
ss.close(); |
|
100
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
81 |
|
50768 | 82 |
(new Thread(this)).start(); |
83 |
serverSoc.startHandshake(); |
|
100
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
84 |
|
50768 | 85 |
boolean closeIsReady = closeCondition.await(90L, TimeUnit.SECONDS); |
86 |
if (!closeIsReady) { |
|
87 |
System.out.println( |
|
88 |
"Ignore, the closure is not ready yet in 90 seconds."); |
|
89 |
return; |
|
100
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
90 |
} |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
91 |
|
50768 | 92 |
socket.setSoLinger(true, 10); |
93 |
System.out.println("Calling Socket.close"); |
|
94 |
socket.close(); |
|
95 |
System.out.println("ssl socket get closed"); |
|
96 |
System.out.flush(); |
|
100
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
97 |
} |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
98 |
|
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
99 |
// block in write |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
100 |
public void run() { |
50768 | 101 |
byte[] ba = new byte[1024]; |
102 |
for (int i = 0; i < ba.length; i++) { |
|
103 |
ba[i] = 0x7A; |
|
104 |
} |
|
105 |
||
100
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
106 |
try { |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
107 |
OutputStream os = socket.getOutputStream(); |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
108 |
int count = 0; |
50768 | 109 |
|
110 |
// 1st round write |
|
111 |
count += ba.length; |
|
112 |
System.out.println(count + " bytes to be written"); |
|
113 |
os.write(ba); |
|
114 |
System.out.println(count + " bytes written"); |
|
115 |
||
116 |
// Signal, ready to close. |
|
117 |
closeCondition.countDown(); |
|
118 |
||
119 |
// write more |
|
100
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
120 |
while (true) { |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
121 |
count += ba.length; |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
122 |
System.out.println(count + " bytes to be written"); |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
123 |
os.write(ba); |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
124 |
System.out.println(count + " bytes written"); |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
125 |
} |
50768 | 126 |
} catch (Exception e) { |
127 |
if (socket.isClosed() || socket.isOutputShutdown()) { |
|
128 |
System.out.println("interrupted, the socket is closed"); |
|
129 |
} else { |
|
130 |
throw new RuntimeException("interrupted?", e); |
|
131 |
} |
|
100
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
132 |
} |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
133 |
} |
50768 | 134 |
} |
100
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
diff
changeset
|
135 |