40

I have a very similar error message to this post; however, the solution on that same post did not work for me. Editing the host file my adding in 127.0.0.1 my-host-name to my hosts file (per solution in linked thread) did nothing for me unfortunately.

After "run" in JDB, I get the following error message:

Initializing jdb ...

run run QuadtreeBitmap VM start exception: VM initialization failed for: /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/bin/java -Xdebug -Xrunjdwp:transport=dt_socket,address=Patricks-iMac.local:50547,suspend=y QuadtreeBitmap

ERROR: transport error 202: gethostbyname: unknown host ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510) JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [debugInit.c:730]

Fatal error: Target VM failed to initialize.

I am using MacOS and trying to launch JDB directly through the terminal (and not through Eclipse or any other IDE).

ptk
  • 6,835
  • 14
  • 45
  • 91
  • 1
    What IP is shown if you do `ping Patricks-iMac.local`? that's the mapping to add to `hosts` file. – LMC May 15 '18 at 20:38
  • @LuisMuñoz you were absolutely correct. I will accept your answer if you decide to write one up! Might be good to make it clear that the hosts file mapping should be specific to the error message for noobs like me. – ptk May 16 '18 at 03:39

3 Answers3

60

In my case problem was related to Java 8. I used Java 9+ syntax for remote debugger:

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005

While for Java 8 you cannot use address in format *:port it suppose to be:

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
JJ Roman
  • 4,225
  • 1
  • 27
  • 21
  • 6
    whoa man, you probably saved hours of my time. I also used to use syntax with `address=*:5005` and was unaware of such difference for java 8. You are awesome, thank you! – bpawlowski Jul 15 '20 at 15:49
  • 2
    This is the right answer, thank you so much! – jpruiz114 Dec 29 '20 at 19:38
  • @jpruiz114 I think original problem of OP might be different. I believe google indexed this question in a way it is found by people like me - when the problem occurs. I am glad I was able to contribute. – JJ Roman Dec 30 '20 at 08:37
  • 2
    A syntax that works for me in both Java versions is `address=0.0.0.0:5005` – cdauth Jan 11 '21 at 14:50
  • `address=*:5005` and `address=*:5005` syntax imply a security risk since debug port will be opened on all interfaces. See accepted answer. – LMC Mar 13 '23 at 19:48
40

The jvm is trying to open the dt_socket at host Patricks-iMac.local, port 50547 but needs first to resolve that host name to an IP address. DNS lookup will fail since it's a dummy hostname assigned to a private address and DNS servers usually don't know about them unless a sysadmin has configured them (companies use to do that). There are two solutions for this:

  1. Add the hostname mapping on hosts file keeping other names configured for that IP
    127.0.0.1 localhost Patricks-iMac.local

  2. Configure the dt_socket by IP address without touching hosts file (recommended)

-Xrunjdwp:transport=dt_socket,address=127.0.0.1:50547

A word on networking troubleshooting:

  • unknown host means DNS problems, TCP connection did not start at all because an IP address was not available.
  • host unreachable means TCP connectivity problems, an IP is known but not reachable because of firewall, routing or other problems. ping to that IP will fail.
  • port unreachable means TCP connectivity problems, the IP is reachable but the port is not because of firewalls, service is down, etc. ping to the IP will work but connections to that port will still fail.

A word on security
The following syntaxes imply a security risk since the debug port will be exposed on all interfaces. Mitigation measures might be good to apply.

address=*:5005
address=0.0.0.0:5005
address=5005 (java 8, binds to loopback interface on java 9+)
LMC
  • 10,453
  • 2
  • 27
  • 52
0

May network admins made some changes in the meantime. Some firewall stuff. Problem is that Eclipse tries to establish connection to JVM at "localhost" (and some random port). You can try this solution.

Unable to debug in Java with eclipse

Komalpreet Singh
  • 165
  • 1
  • 10