United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6339385 : JVM crash when JDWP port is "pinged" or "scanned" (handshake fails)

Details
Type:
Bug
Submit Date:
2005-10-20
Status:
Closed
Updated Date:
2011-12-29
Project Name:
JDK
Resolved Date:
2005-10-20
Component:
core-svc
OS:
linux
Sub-Component:
debugger
CPU:
x86
Priority:
P4
Resolution:
Duplicate
Affected Versions:
5.0
Fixed Versions:

Related Reports

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.5.0_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode, sharing)


Also seen on non-Sun JVMs: JRockit (1.5.0_04), Apple (1.5.0_05)

ADDITIONAL OS VERSION INFORMATION :
Linux snidely 2.4.22-1.2115.nptl #1 Wed Oct 29 15:42:51 EST 2003 i686 i686 i386 GNU/Linux

Also seen on Windows

EXTRA RELEVANT SYSTEM CONFIGURATION :
Starting JVM with these options
 -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8453

A DESCRIPTION OF THE PROBLEM :
When starting a java process with the argument:
    -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8453

If that port (8453) is "pinged" by something other than JDWP, then the JVM crashes with:

ERROR: transport error 202: handshake failed - connection prematurally closed ["transport.c",L41]
JDWP exit error JVMTI_ERROR_NONE(0): could not connect, timeout or fatal error

and exits with a success status (0).

This has happened for servers running tests with debugging turned on.  I think the culprit was probably a virus doing a port scan or something.

This seems like bad behavior.  If some non-JDWP thing connects, that connection should be simply refused without crashing.

If you must insist on crashing the JVM, please exit with non-successful status.




STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Start JVM with
    -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8453

and do something like a port scan or a new Socket() or point a web browser at port 8453.


With the attached code:
java  -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8453  CrashJdwp

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Without the -agentlib settings:
    java CrashJdwp
you should see something like this:
    tick tick tick tick
    Connecting to 8453...
    Unable to connect to 8453: java.net.ConnectException: Connection refused
    tick tick tick tick tick tick
    Exiting Ticker

I'd expect that with -agentlib turned on, you might want to see something like this:
    tick tick tick tick
    Connecting to 8453...
    ERROR: transport error 202: handshake failed - connection prematurally closed ["transport.c",L41]
    JDWP ignoring connection...
    Successfully connected to 8453
    tick tick tick tick tick tick
    Exiting Ticker

ACTUAL -
$ java  -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8453  CrashJdwp
Listening for transport dt_socket at address: 8453
tick tick tick tick
Connecting to 8453...
ERROR: transport error 202: handshake failed - connection prematurally closed ["transport.c",L41]
JDWP exit error JVMTI_ERROR_NONE(0): could not connect, timeout or fatal error
$ echo $?
0


ERROR MESSAGES/STACK TRACES THAT OCCUR :
ERROR: transport error 202: handshake failed - connection prematurally closed ["transport.c",L41]
JDWP exit error JVMTI_ERROR_NONE(0): could not connect, timeout or fatal error


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;

/**
 * This will crash the JVM if JDWP is listening on port 8453
 *
 * <p/>
 * Run this way:
 * <pre>
 *    java CrashJdwp
 * </pre>
 * and you should see something like:
 * <pre>
 *    tick tick tick tick
 *    Connecting to 8453...
 *    Unable to connect to 8453: java.net.ConnectException: Connection refused
 *    tick tick tick tick tick tick
 *    Exiting Ticker
 * </pre>
 * <p/>
 * However, if run this way:
 * <pre>
 *    java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8453 CrashJdwp
 * </pre>
 * you will see:
 * <pre>
 *    Listening for transport dt_socket at address: 8453
 *    tick tick tick tick
 *    Connecting to 8453...
 *    ERROR: transport error 202: handshake failed - connection prematurally closed ["transport.c",L41]
 *    JDWP exit error JVMTI_ERROR_NONE(0): could not connect, timeout or fatal error
 * </pre>
 * and the JVM exits.
 *
 * Further, it exits (linux) with a <b>zero status</b> value (success).
 */
public class CrashJdwp
{
    public static void main( String[] args ) throws Exception
    {

        new Thread() {
            @Override public void run() {
                for ( int i = 0; i < 10; ++i ) {
                    try {
                        sleep(1000);
                    } catch ( InterruptedException ignore ) { }
                    System.out.print( "tick " );
                }
                System.out.println( "\nExiting Ticker" );
            }
        }.start();
        
        
        Thread.sleep(5000);

        System.out.println( "\nConnecting to 8453..." );

        try {
            Socket s = new Socket( InetAddress.getLocalHost(), 8453);
            s.close();
            System.out.println("\nSuccessfully connected to 8453");
        }
        catch (IOException e)
        {
            System.out.println("\nUnable to connect to 8453: " + e );
        }
        
    }

}

---------- END SOURCE ----------

                                    

Comments
EVALUATION

This was fixed in mustang b49 as 6306165.
                                     
2005-10-20



Hardware and Software, Engineered to Work Together