1 /*
2 * Copyright (c) 1998, 2004, 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 */
41 * the protocol. For now, the common case is the closing of an idle
42 * connection by a loaded/bored/dead server host.
43 *
44 * The fix is/was to trivially attempt to execute a non-blocking read
45 * on the connection before reusing it, to see if an exception/EOF is
46 * waiting for delivery. This is a 99%/1% solution, but until the
47 * great protocol rewrite, it's the best option.
48 *
49 * Reproducing is by establishing a connection to a registry and
50 * killing/restarting that registry (this forces the TCP connection
51 * to close). The next call to the registry will use the (stale)
52 * cached connection, and will fail without the bugfix.
53 */
54
55 import java.io.*;
56 import java.rmi.*;
57 import java.rmi.registry.*;
58 import java.rmi.server.*;
59
60 public class DeadCachedConnection {
61 static public final int regport = 17340;
62
63 static public void main(String[] argv)
64 throws Exception {
65 // establish the registry (we hope)
66 System.err.println ("Starting registry on port " + regport);
67 DeadCachedConnection.makeRegistry(regport);
68
69 // Get a handle to the registry
70 Registry reg = null;
71 System.err.println ("Locating just-started registry...");
72 try {
73 reg = LocateRegistry.getRegistry(regport);
74 } catch (RemoteException e) {
75 throw new InternalError ("Can't find registry after starting it.");
76 }
77
78 // Contact the registry by invoking something on it.
79 System.err.println ("Connecting to registry...");
80 String[] junk = reg.list();
81
|
1 /*
2 * Copyright (c) 1998, 2012, 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 */
41 * the protocol. For now, the common case is the closing of an idle
42 * connection by a loaded/bored/dead server host.
43 *
44 * The fix is/was to trivially attempt to execute a non-blocking read
45 * on the connection before reusing it, to see if an exception/EOF is
46 * waiting for delivery. This is a 99%/1% solution, but until the
47 * great protocol rewrite, it's the best option.
48 *
49 * Reproducing is by establishing a connection to a registry and
50 * killing/restarting that registry (this forces the TCP connection
51 * to close). The next call to the registry will use the (stale)
52 * cached connection, and will fail without the bugfix.
53 */
54
55 import java.io.*;
56 import java.rmi.*;
57 import java.rmi.registry.*;
58 import java.rmi.server.*;
59
60 public class DeadCachedConnection {
61 static public final int regport = TestLibrary.getUnusedRandomPort();
62
63 static public void main(String[] argv)
64 throws Exception {
65 // establish the registry (we hope)
66 System.err.println ("Starting registry on port " + regport);
67 DeadCachedConnection.makeRegistry(regport);
68
69 // Get a handle to the registry
70 Registry reg = null;
71 System.err.println ("Locating just-started registry...");
72 try {
73 reg = LocateRegistry.getRegistry(regport);
74 } catch (RemoteException e) {
75 throw new InternalError ("Can't find registry after starting it.");
76 }
77
78 // Contact the registry by invoking something on it.
79 System.err.println ("Connecting to registry...");
80 String[] junk = reg.list();
81
|