23

I am trying to debug a simple Java application on my machine using Eclipse as an IDE. When I try to debug the application by entering the Debug Perspective, I set a breakpoint and start debug. Within a few seconds, the following pop-up window:

Launching unicodeRead has encountered a problem. Cannot connect to VM.

The message dumped on the console is as follows:

ERROR: transport error 202: connect failed: Connection refused
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [../../../src/share/back/debugInit.c:708]
FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)  

How do I correct this? Why does this happen?

Sriram
  • 10,298
  • 21
  • 83
  • 136
  • 3
    Is there another process running in debug mode already? The port might be busy. – James DW Sep 20 '11 at 15:17
  • @JamesDW: how do I check that? I do not have any other debuggers (gdb/ddd) on. – Sriram Sep 20 '11 at 15:20
  • 2
    @JamesDW probably he would be getting `ERROR: transport error 202: bind failed: Address already in use ` in case the port was already in use. – Xavi López Sep 20 '11 at 15:25
  • @Sriram Which parameters are you starting the jvm with? – Xavi López Sep 20 '11 at 15:25
  • @XaviLópez: I am a complete noob as far as Java goes. I don't think I have specifically mentioned any parameters. I just hit the build and run buttons to run the program. How do I check what parameters I am running jvm with? – Sriram Sep 20 '11 at 16:34
  • @Sriram is it a standalone application you're trying to debug, or is it a webapp running on a web server? I think in the debug configuration options you can see those parameters maybe in 'Environment' tab, I don't remember the details. – Xavi López Sep 20 '11 at 17:40
  • @XaviLópez: This is a standalone application. Nothing is over the web. – Sriram Sep 20 '11 at 17:58

12 Answers12

28

I just had the same problem.

Yesterday everything worked fine, now nothing - same error as you gave. I found out that 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). When I tried pinging localhost (or 127.0.0.1) I got following:

C:\Windows\system32>ping 127.0.0.1
Pinging 127.0.0.1 with 32 bytes of data:
PING: transmit failed. General failure.
PING: transmit failed. General failure.
PING: transmit failed. General failure.
PING: transmit failed. General failure.

and

C:\Windows\system32>ping localhost
Ping request could not find host localhost. Please check the name and try again.

It seams that in some cases DNS is expected to resolve this, and if firewall prevents localhost requests to DNS - stuff breaks. I had to alter hosts file and remove comments in following lines, so I would not rely on DNS for this anymore:

# 127.0.0.1       localhost
# ::1             localhost

Although it is written that hosts file changes take effect immediately, I think that some processes locked this and restart was necessary in my case. After that, everything worked again.

gonadarian
  • 601
  • 7
  • 13
  • 2
    I had this problem in OS X 10. I noticed that I had a second entry for localhost in my hosts file that was pointing to my LAN address. Removing that second entry solved my problem (but I would have never noticed it without running the ping!) – Mike Feb 11 '15 at 16:32
  • Worked for me. No need to restart. Thanks! – Faliorn May 11 '16 at 18:31
  • it worked for me, i removed duplicate localhost in host file, thats all. – Eswar Goud Oct 04 '16 at 16:47
  • I'm using Intellij and the debugger is working just fine when I'm using the "Platform test runner" but when I debug using "gradle test runner" I get the same error codes. I've tried restarting, killing java processes, firewall is off and pinging localhost, 127.0.0.1 and ::1 all of them are reachable. None of the solutions worked for me. Any other successful solution? – cnova Nov 11 '16 at 06:23
  • I am facing the same problem. The only noticeable thing is that it occurs only when I am connected to our company's network. When I am connected to some other network, debug works fine. Any suggestion to fix the problem? – sshah Mar 28 '17 at 05:56
  • Same problem with my OSX, add 127.0.0.1 localhost then it works fine – Bargitta Apr 03 '18 at 08:25
7

Had same problem, but the solution was to run the application with -server=y option and not with -server=n.

Before:

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

After:

java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=localhost:5005
vladimirror
  • 729
  • 12
  • 8
  • This solved the issue for me. Worth noting it seems server defaults to n, as I wasn't setting server at all. – William Oliver May 20 '20 at 21:37
  • Do you know how I can configure this option in vscode using the `launch.json` config? – tarekahf Nov 24 '22 at 07:25
  • 1
    @tarekahf I am not sure how "on topic" your question is, but I am happy to help, and the SO seems to have these answers. I never tested them myself though. https://stackoverflow.com/questions/61700234/how-to-set-java-vmargs-in-vscode-at-workspace-level https://stackoverflow.com/questions/60305138/vscode-java-test-config-vmargs-not-working – vladimirror Nov 24 '22 at 16:50
  • @vladimirror thanks a lot. I tried that option and looks like it won't work since I am using `launch request` as opposed to `attach request`. I think if you use `server=y` you much change it to `attach request` to make it work. This needs more effort. I will check it out. – tarekahf Nov 24 '22 at 19:10
5

I was seeing an error while using the -X format:

java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=n myapp

The error went away when I switched to the newer format:

java -agentlib:jdwp=transport=dt_socket,server=y,address=4000,suspend=n myapp
user674669
  • 10,681
  • 15
  • 72
  • 105
5

Looks like the same problem as here. A reboot of the pc fixed the problem there. I haven't found any other solutions.

Maza89
  • 518
  • 4
  • 12
2

Its Very Simple,Just do the Following Changes in eclipse.ini file.

-vm
binary\com.sun.java.jdk.win32.x86_1.6.0.u43\jre\bin\javaw.exe
Micha
  • 5,117
  • 8
  • 34
  • 47
Calix
  • 21
  • 3
2

I changed

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

to

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

and that did the trick!

Maximouse
  • 4,170
  • 1
  • 14
  • 28
Andreas
  • 21
  • 2
0

My case is I have a bunch of domains refer to 127.0.0.1 in hosts file, like this:

127.0.0.1 localhost domian1.local domain2.local domain3.local

one day I added another new domain to refer to 127.0.0.1. By mistake, I put the domain in front of "localhost", like this:

127.0.0.1 domain4.local localhost domian1.local domain2.local domainx.local

After this, I always got an alert window in eclipse while debugging:

Cannot connect to VM com.sun.jdi.connect.TransportTimeoutException

In console:

ERROR: transport error 202: connect failed: Connection refused ERROR: JDWP: Failed to initialize transport via localhost:50470, trying localhost via 127.0.0.1:50470 FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197) ERROR: transport error 202: connect failed: Connection refused ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510) JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [../../../src/share/back/debugInit.c:690]

The solution is keep "localhost" at the first position all the time.

127.0.0.1 localhost domian1.local domain2.local domainx.local domain4.local

Willie Z
  • 476
  • 7
  • 12
0

What solved for me was deleting the entire domain1 folder inside the domains folder on glassfish main folder. Eclipse will ask you to recreate a domain and then everything works again.

Carlos ABS
  • 693
  • 9
  • 19
0

In eclipse select Run tab -> Debug configuration -> Junit -> select your test name -> Environment tab -> add variable server=y .

-1

I was getting the same error on my ubuntu machine because of a mishap with the /etc/hosts file. I had commented out the mapping of localhost to 127.0.0.1, and to complicate matters further there was a swap file hanging around.

This was the first line of my /etc/hosts:

127.0.0.1       #localhost

Deleting the # fixed the problem, whereas rebooting understandably had not.

Adair
  • 1,697
  • 18
  • 22
-1

My cause & solution were completely different.
I think in my case it was due to the installation of JProfiler. I fixed it by uninstalling JProfiler and launching eclipse with the -clean option. I suspect that JProfiler was inserting itself in the debugger. The -clean option forces Eclipse to re-assess its plugins, so that alone might have been sufficient.

Didjit
  • 785
  • 2
  • 8
  • 26
-3

Continuing @gonadarian's answer, it seems Eclipse uses port 127.0.0.1 for debug purposes. This port is also called localhost. The way this error can be removed is by ensuring that there are no processes or services running on the above ports. The way to do this, on Linux is:

  1. As root, enter the command:
    netstat -tulpn | grep 127.0.0.1

  2. If there are processes running on the above port, it will show up in the format:
    process_id/process name.

  3. Kill the above processes like so: kill -KILL process_id

  4. Restart the computer for these changes to take effect. The error should no longer occur.

Sriram
  • 10,298
  • 21
  • 83
  • 136