Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/rmi/transport/tcp/DeadCachedConnection.java
38855 views
1
/*
2
* Copyright (c) 1998, 2013, 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
/* @test
25
* @bug 4094891
26
* @summary unable to retry call if cached connection to server is used
27
* @library ../../../../java/rmi/testlibrary
28
* @build TestLibrary JavaVM
29
* @run main/othervm DeadCachedConnection
30
*/
31
32
/* Fault: Cached connections used for remote invocations exhibited
33
* failure (sudden EOF or a TCP-related exception) immediately on
34
* sending a new request. It was then impossible to tell whether the
35
* connection had managed to transport the request before dying; even
36
* deserialization of request arguments is non-idempotent in general.
37
*
38
* In fact, this problem cannot be solved generally without rewriting
39
* the protocol. For now, the common case is the closing of an idle
40
* connection by a loaded/bored/dead server host.
41
*
42
* The fix is/was to trivially attempt to execute a non-blocking read
43
* on the connection before reusing it, to see if an exception/EOF is
44
* waiting for delivery. This is a 99%/1% solution, but until the
45
* great protocol rewrite, it's the best option.
46
*
47
* Reproducing is by establishing a connection to a registry and
48
* killing/restarting that registry (this forces the TCP connection
49
* to close). The next call to the registry will use the (stale)
50
* cached connection, and will fail without the bugfix.
51
*/
52
53
import java.io.*;
54
import java.rmi.*;
55
import java.rmi.registry.*;
56
import java.rmi.server.*;
57
58
public class DeadCachedConnection {
59
static public final int regport = TestLibrary.getUnusedRandomPort();
60
61
static public void main(String[] argv)
62
throws Exception {
63
// establish the registry (we hope)
64
System.err.println ("Starting registry on port " + regport);
65
DeadCachedConnection.makeRegistry(regport);
66
67
// Get a handle to the registry
68
Registry reg = null;
69
System.err.println ("Locating just-started registry...");
70
try {
71
reg = LocateRegistry.getRegistry(regport);
72
} catch (RemoteException e) {
73
throw new InternalError ("Can't find registry after starting it.");
74
}
75
76
// Contact the registry by invoking something on it.
77
System.err.println ("Connecting to registry...");
78
String[] junk = reg.list();
79
80
// Kill and restart the registry
81
System.err.println("Killing registry...");
82
DeadCachedConnection.killRegistry();
83
System.err.println("Restarting registry...");
84
DeadCachedConnection.makeRegistry(regport);
85
86
// Try again (this is the test)
87
System.err.println("Trying to use registry in spite of stale cache...");
88
junk = reg.list();
89
90
// we're happy
91
System.err.println("Test succeeded.");
92
try {
93
DeadCachedConnection.killRegistry();
94
} catch (Exception foo) {
95
}
96
}
97
98
public static void makeRegistry(int p) {
99
// sadly, we can't kill a registry if we have too-close control
100
// over it. We must make it in a subprocess, and then kill the
101
// subprocess when it has served our needs.
102
103
try {
104
JavaVM jvm =
105
new JavaVM("sun.rmi.registry.RegistryImpl", "", Integer.toString(p));
106
jvm.start();
107
DeadCachedConnection.subreg = jvm;
108
109
} catch (IOException e) {
110
// one of these is summarily dropped, can't remember which one
111
System.out.println ("Test setup failed - cannot run rmiregistry");
112
TestLibrary.bomb("Test setup failed - cannot run test", e);
113
}
114
// Slop - wait for registry to come up. This is stupid.
115
try {
116
Thread.sleep (5000);
117
} catch (Exception whatever) {
118
}
119
}
120
private static JavaVM subreg = null;
121
122
public static void killRegistry() {
123
if (DeadCachedConnection.subreg != null) {
124
DeadCachedConnection.subreg.destroy();
125
try { Thread.sleep(2000); } catch (InterruptedException ie) {}
126
}
127
DeadCachedConnection.subreg = null;
128
}
129
}
130
131