Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java JDB: ERROR: transport error 202: gethostbyname: unknown host

Tags:

java

debugging

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).

like image 898
p4t Avatar asked May 15 '18 07:05

p4t


1 Answers

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+) 
like image 182
LMC Avatar answered Oct 04 '22 05:10

LMC