How to have Eclipse Remote Debugger keep listening on port until a JVM finally connects?

10,006

Turning comment into answer for folks that come by later:

It's possible to specify server=n in the -Xrunjdwp switch and have the debugee connect as a client to the debugger server.

To make this work, the debugger configuration should be set up with the "Socket Listen" option in eclipse like so:

Eclipse debugger configuration

Client can then be started with:

java -Xdebug -Xrunjdwp:transport=dt_socket,server=n,suspend=n,address=8000 -jar foo.jar

Or similar.

Share:
10,006
Nicholas DiPiazza
Author by

Nicholas DiPiazza

Software Developer for American Family Insurance.

Updated on July 19, 2022

Comments

  • Nicholas DiPiazza
    Nicholas DiPiazza almost 2 years

    I have a complicated application with several different JVMs.

    JVM 1 does about 5 minutes of work and then fires off another JVM2 to do some extra work.

    I want to Debug JVM2. So I turn on a remote socket debugger on JVM2's startup script:

    -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000

    And I set up my Eclipse Remote Debug Session like this:

    Connection Type: Standard (Socket Attach), Host: localhost, Port: 8000

    If I wait for JVM2 to start, then launch the debugger, it works fine.

    However it is REALLY hard to pay enough attention to click the debugger after 5 long minutes of waiting.

    If I launch the remote debugger before JVM2 is on... I get

    Failed to connect to remote VM. Connection refused.
    Connection refused: connect
    

    Is there someway to have the Remote Debugger continuously try to connect?

    I tried to use the Eclipse Remote Debug Connection Type: Socket Listen but this blocks the port and JVM2 gives this error on startup:

    FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=JVMTI_ERROR_INTERNAL(113)
    ERROR: transport error 202: bind failed: Address already in use ["transport.c",L41]
    ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510) ["debugInit.c",L500]
    JDWP exit error JVMTI_ERROR_INTERNAL(113): No transports initialized
    

    How can I have the remote debugger try over and over and over again?

    • Jim Garrison
      Jim Garrison over 9 years
      This is the way remote debugging works. The connection goes from the debugger to the remote JVM being debugged. If you want you can add the suspend=y option to have the remote JVM pause until the debugger connects. The remote JVM will not initiate an outgoing JDWP connection.
    • clstrfsck
      clstrfsck over 9 years
      I'm not expert in this at all, but isn't it possible to specify server=n in the -Xrunjdwp switch and have the debugee connect as a client to the debugger server, per your second setup ("Socket Listen") in eclipse?
    • Nicholas DiPiazza
      Nicholas DiPiazza over 9 years
      @JimGarrison i'm trying that now.
    • Nicholas DiPiazza
      Nicholas DiPiazza over 9 years
      @msandiford i'm trying your suggestion next. for some reason IE8 (which i'm stuck using at work) didn't show me your comment until now. That sounds like another acceptible answer. both of your guys' comments are very valid.
    • Nicholas DiPiazza
      Nicholas DiPiazza over 9 years
      @msandiford THIS was the answer i was looking for. Worked great.
  • clstrfsck
    clstrfsck over 9 years
    Adding a rejected edit from @Nicholas as a comment, as it seems relevant: Drawback: If JVM2 is fired off, then is terminated, then fires off again, you'll get an error saying there is no server listening to port 8000 to connect to. Another possibility is to leave your application as a server=y, but add suspend=y which tells the JVM to wait for you to connect with Eclipse in attach mode before launching the program. This will make it so when the 2nd JVM finally goes, it will wait for the remote debugger to connect before launching.
  • Nicholas DiPiazza
    Nicholas DiPiazza over 9 years
    My original question came from the need to debug a program after waiting for a long time, then to re-run that program 3 more times. so yes it was relevant