test/jdk/sun/security/ssl/SSLSocketImpl/SSLSocketCloseHang.java
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 47874 a7d101e56b36
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47271
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
     1
/*
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
     4
 *
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
     7
 * published by the Free Software Foundation.
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
     8
 *
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    13
 * accompanied this code).
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    14
 *
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    18
 *
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    21
 * questions.
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    22
 */
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    23
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    24
/*
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    25
 * @test
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    26
 * @bug 8184328
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    27
 * @summary JDK8u131-b34-socketRead0 hang at SSL read
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    28
 * @run main/othervm SSLSocketCloseHang
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    29
 */
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    30
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    31
import java.io.*;
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    32
import java.net.*;
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    33
import java.util.*;
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    34
import java.security.*;
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    35
import javax.net.ssl.*;
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    36
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    37
public class SSLSocketCloseHang {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    38
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    39
    /*
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    40
     * =============================================================
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    41
     * Set the various variables needed for the tests, then
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    42
     * specify what tests to run on each side.
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    43
     */
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    44
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    45
    /*
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    46
     * Should we run the client or server in a separate thread?
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    47
     * Both sides can throw exceptions, but do you have a preference
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    48
     * as to which side should be the main thread.
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    49
     */
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    50
    static boolean separateServerThread = true;
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    51
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    52
    /*
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    53
     * Where do we find the keystores?
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    54
     */
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    55
    static String pathToStores = "../../../../javax/net/ssl/etc";
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    56
    static String keyStoreFile = "keystore";
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    57
    static String trustStoreFile = "truststore";
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    58
    static String passwd = "passphrase";
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    59
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    60
    /*
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    61
     * Is the server ready to serve?
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    62
     */
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    63
    volatile static boolean serverReady = false;
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    64
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    65
    /*
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    66
     * Was the client responsible for closing the socket
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    67
     */
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    68
    volatile static boolean clientClosed = false;
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    69
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    70
    /*
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    71
     * Turn on SSL debugging?
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    72
     */
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    73
    static boolean debug = false;
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    74
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    75
    /*
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    76
     * If the client or server is doing some kind of object creation
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    77
     * that the other side depends on, and that thread prematurely
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    78
     * exits, you may experience a hang.  The test harness will
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    79
     * terminate all hung threads after its timeout has expired,
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    80
     * currently 3 minutes by default, but you might try to be
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    81
     * smart about it....
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    82
     */
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    83
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    84
    /*
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    85
     * Define the server side of the test.
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    86
     *
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    87
     * If the server prematurely exits, serverReady will be set to true
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    88
     * to avoid infinite hangs.
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    89
     */
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    90
    void doServerSide() throws Exception {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    91
        SSLServerSocketFactory sslssf =
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    92
            (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    93
        SSLServerSocket sslServerSocket =
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    94
            (SSLServerSocket) sslssf.createServerSocket(serverPort);
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    95
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    96
        serverPort = sslServerSocket.getLocalPort();
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    97
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    98
        /*
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
    99
         * Signal Client, we're ready for his connect.
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   100
         */
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   101
        serverReady = true;
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   102
47874
a7d101e56b36 8189646: sun/security/ssl/SSLSocketImpl/SSLSocketCloseHang.java failed with "java.net.SocketTimeoutException: Read timed out"
robm
parents: 47271
diff changeset
   103
        System.err.println("Server accepting: " + System.nanoTime());
47271
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   104
        SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
47874
a7d101e56b36 8189646: sun/security/ssl/SSLSocketImpl/SSLSocketCloseHang.java failed with "java.net.SocketTimeoutException: Read timed out"
robm
parents: 47271
diff changeset
   105
        System.err.println("Server accepted: " + System.nanoTime());
47271
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   106
        sslSocket.startHandshake();
47874
a7d101e56b36 8189646: sun/security/ssl/SSLSocketImpl/SSLSocketCloseHang.java failed with "java.net.SocketTimeoutException: Read timed out"
robm
parents: 47271
diff changeset
   107
        System.err.println("Server handshake complete: " + System.nanoTime());
47271
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   108
        while (!clientClosed) {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   109
            Thread.sleep(500);
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   110
        }
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   111
    }
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   112
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   113
    /*
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   114
     * Define the client side of the test.
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   115
     *
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   116
     * If the server prematurely exits, serverReady will be set to true
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   117
     * to avoid infinite hangs.
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   118
     */
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   119
    void doClientSide() throws Exception {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   120
        boolean caught = false;
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   121
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   122
        /*
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   123
         * Wait for server to get started.
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   124
         */
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   125
        System.out.println("waiting on server");
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   126
        while (!serverReady) {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   127
            Thread.sleep(50);
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   128
        }
47874
a7d101e56b36 8189646: sun/security/ssl/SSLSocketImpl/SSLSocketCloseHang.java failed with "java.net.SocketTimeoutException: Read timed out"
robm
parents: 47271
diff changeset
   129
        Thread.sleep(500);
47271
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   130
        System.out.println("server ready");
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   131
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   132
        Socket baseSocket = new Socket("localhost", serverPort);
47874
a7d101e56b36 8189646: sun/security/ssl/SSLSocketImpl/SSLSocketCloseHang.java failed with "java.net.SocketTimeoutException: Read timed out"
robm
parents: 47271
diff changeset
   133
        baseSocket.setSoTimeout(1000);
47271
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   134
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   135
        SSLSocketFactory sslsf =
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   136
            (SSLSocketFactory) SSLSocketFactory.getDefault();
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   137
        SSLSocket sslSocket = (SSLSocket)
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   138
            sslsf.createSocket(baseSocket, "localhost", serverPort, false);
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   139
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   140
        // handshaking
47874
a7d101e56b36 8189646: sun/security/ssl/SSLSocketImpl/SSLSocketCloseHang.java failed with "java.net.SocketTimeoutException: Read timed out"
robm
parents: 47271
diff changeset
   141
        System.err.println("Client starting handshake: " + System.nanoTime());
47271
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   142
        sslSocket.startHandshake();
47874
a7d101e56b36 8189646: sun/security/ssl/SSLSocketImpl/SSLSocketCloseHang.java failed with "java.net.SocketTimeoutException: Read timed out"
robm
parents: 47271
diff changeset
   143
        System.err.println("Client handshake done: " + System.nanoTime());
47271
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   144
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   145
        Thread.sleep(500);
47874
a7d101e56b36 8189646: sun/security/ssl/SSLSocketImpl/SSLSocketCloseHang.java failed with "java.net.SocketTimeoutException: Read timed out"
robm
parents: 47271
diff changeset
   146
        System.err.println("Client closing: " + System.nanoTime());
47271
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   147
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   148
        sslSocket.close();
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   149
        clientClosed = true;
47874
a7d101e56b36 8189646: sun/security/ssl/SSLSocketImpl/SSLSocketCloseHang.java failed with "java.net.SocketTimeoutException: Read timed out"
robm
parents: 47271
diff changeset
   150
        System.err.println("Client closed: " + System.nanoTime());
47271
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   151
    }
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   152
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   153
    /*
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   154
     * =============================================================
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   155
     * The remainder is just support stuff
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   156
     */
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   157
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   158
    // use any free port by default
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   159
    volatile int serverPort = 0;
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   160
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   161
    volatile Exception serverException = null;
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   162
    volatile Exception clientException = null;
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   163
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   164
    volatile byte[] serverDigest = null;
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   165
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   166
    public static void main(String[] args) throws Exception {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   167
        String keyFilename =
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   168
            System.getProperty("test.src", "./") + "/" + pathToStores +
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   169
                "/" + keyStoreFile;
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   170
        String trustFilename =
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   171
            System.getProperty("test.src", "./") + "/" + pathToStores +
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   172
                "/" + trustStoreFile;
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   173
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   174
        System.setProperty("javax.net.ssl.keyStore", keyFilename);
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   175
        System.setProperty("javax.net.ssl.keyStorePassword", passwd);
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   176
        System.setProperty("javax.net.ssl.trustStore", trustFilename);
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   177
        System.setProperty("javax.net.ssl.trustStorePassword", passwd);
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   178
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   179
        if (debug)
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   180
            System.setProperty("javax.net.debug", "all");
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   181
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   182
        /*
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   183
         * Start the tests.
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   184
         */
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   185
        new SSLSocketCloseHang();
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   186
    }
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   187
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   188
    Thread clientThread = null;
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   189
    Thread serverThread = null;
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   190
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   191
    /*
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   192
     * Primary constructor, used to drive remainder of the test.
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   193
     *
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   194
     * Fork off the other side, then do your work.
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   195
     */
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   196
    SSLSocketCloseHang() throws Exception {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   197
        if (separateServerThread) {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   198
            startServer(true);
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   199
            startClient(false);
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   200
        } else {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   201
            startClient(true);
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   202
            startServer(false);
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   203
        }
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   204
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   205
        /*
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   206
         * Wait for other side to close down.
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   207
         */
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   208
        if (separateServerThread) {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   209
            serverThread.join();
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   210
        } else {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   211
            clientThread.join();
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   212
        }
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   213
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   214
        /*
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   215
         * When we get here, the test is pretty much over.
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   216
         *
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   217
         * If the main thread excepted, that propagates back
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   218
         * immediately.  If the other thread threw an exception, we
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   219
         * should report back.
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   220
         */
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   221
        if (serverException != null) {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   222
            System.out.print("Server Exception:");
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   223
            throw serverException;
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   224
        }
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   225
        if (clientException != null) {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   226
            System.out.print("Client Exception:");
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   227
            throw clientException;
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   228
        }
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   229
    }
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   230
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   231
    void startServer(boolean newThread) throws Exception {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   232
        if (newThread) {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   233
            serverThread = new Thread() {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   234
                public void run() {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   235
                    try {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   236
                        doServerSide();
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   237
                    } catch (Exception e) {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   238
                        /*
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   239
                         * Our server thread just died.
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   240
                         *
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   241
                         * Release the client, if not active already...
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   242
                         */
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   243
                        System.err.println("Server died...");
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   244
                        System.err.println(e);
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   245
                        serverReady = true;
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   246
                        serverException = e;
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   247
                    }
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   248
                }
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   249
            };
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   250
            serverThread.start();
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   251
        } else {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   252
            doServerSide();
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   253
        }
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   254
    }
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   255
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   256
    void startClient(boolean newThread) throws Exception {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   257
        if (newThread) {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   258
            clientThread = new Thread() {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   259
                public void run() {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   260
                    try {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   261
                        doClientSide();
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   262
                    } catch (Exception e) {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   263
                        /*
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   264
                         * Our client thread just died.
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   265
                         */
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   266
                        System.err.println("Client died...");
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   267
                        clientException = e;
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   268
                    }
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   269
                }
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   270
            };
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   271
            clientThread.start();
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   272
        } else {
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   273
            doClientSide();
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   274
        }
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   275
    }
dc9b1da1314b 8184328: JDK 8u131 socketRead0 hang at SSL read
robm
parents:
diff changeset
   276
}