handshake failed error with Remote Debugging
Answered
Hi,
When I try remote debugging on my mac it work without any problem but when I'm try it from on local vagrant box machine i got the following exception in the event log
Error running retailapp: Unable to open debugger port : java.io.IOException "handshake failed - connection prematurally closed"
i used the following command to run the jar on the local vagrant box
$ java -Xdebug -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar myjar.jar
That is after i have made prot forwarding for the fort 5005 in the Vagrantfile
override.vm.network "forwarded_port", guest: 5005, host: 5005, protocol: 'tcp' # InteliJ Debugger
and used the following remote configuration on IntelliJ
Please sign in to leave a comment.
Hi Everyone,
Did you solve this problem? I've got same error now. If you solved, could you please help me to solve.
Thank you
The error you described is completely different:
The initial error:
Your error:
In your case, remote debugger needs to connect to the JVM that is already running in debug mode. Make sure you start the app you want to debug first with the JVM options suggested by the IDE. Then start Remote configuration to connect and debug this app.
Also, make sure that localhost is configured in your hosts file like that:
Hi Konstantin,
Thank you for your kind reply.
You're right. When I choose port address other than 5005 I've got above error. But when I used 5005 I've got following error.
Is your process is inside Docker? That could be this case:
https://stackoverflow.com/questions/46662125/remote-debugging-java-9-in-a-docker-container-from-intellij-idea/47772365#47772365
No! it is not inside Docker.
May you show the command how the application is started?
I am using debug button instead command for starting application.
When I clicked debug button I've got error with above settings.
This configuration (RemoteDebug) is used to connect to an already running process. In case you want to start an application in debug mode, please use "Application" Run/Debug configuration:
https://www.jetbrains.com/help/idea/debugging-your-first-java-application.html
Konstantin,
Really, I appreciate for your patience.
I can give info briefly about my project and what we wanted to do. We have project running on openshift and I want to debug that project via IntelliJ. When I search on the Internet, I've found above settings to apply and I applied. But I've got error as we've mentioned before.
Thank you again.
Ah, I see. AFAIK, OpenShift is also a containerization solution like docker, Virtuozzo, etc. So, the same solution is valid here.
Let me describe the situation as I see it:
A java application runs inside the OpenShift container. This Java application is started with some arguments like that:
In case of running the application using this command, the application's debugger will accept connections only from the localhost (from the container itself). But in your case the debugger should accept connections from IntelliJ IDEA (this is another host from container's point of view). To pass the information that connections should be accepted from anywhere including IntelliJ IDEA, it is needed to change
address=5005
withaddress=*:5005
.You need to go into the openshift container with your application and edit application's configuration file, so it would start like that:
I am trying both of them. But error is still continue.
Firstly, I built project successfully. Then I typed following command to terminal and entered. Project started successfully. I expected to see message like "Listening for transport dt_socket at address 5005". But I didnt see message.
java -jar -Dspring.profiles.active=dev -Dspring-boot.run.jvmArguments="-Xdebug -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005" myproject-0.0.1-SNAPSHOT.jar
After started project then I clicked debug button, unfortunately I had same error.
Also, I watched youtube video at following address and I did the completely same thing;
https://www.youtube.com/watch?v=jA1wHbAK_T0
At the end I've two issue; one of this is not see message like "Listening for transport dt_socket at address 5005",
and other is
Please change the address in your command as I stated in the previous message:
Your (address=5005):
Needed (address=*:5005):
I've changed. But the error still continues.
Can you show the output of the netstat command from inside the container once the application is started? It is needed to check that debugger is listening on all interfaces. In case container is linux-based, that should look like that:
I am using windows ;
Am I right that Windows is the OS where IntelliJ IDEA is installed? And your application is running inside OpenShift container (which is most probably running some kind of Linux)? If so, please check the output of netstat inside the OpenShift container.
Yes you're right. But I couldn't use netstat command. When I used I've got "command not found". How can I check the output of netstat inside the OpenShift container?
Hi Everyone,
I am experiencing the same problem, below is an image with my configuration:
Hi Bosa,
I've solved this problem. If you are trying Openshift for remote server, please remove localhost word from your settings as must be following;
Then add JAVA_DEBUG and JAVA_TOOL_OPTIONS as following to your openshift deployment.
Unfortunately I am not using OpenShift, but I am using Docker for my remote server
Then please find same settings on internet for docker and add.
Make sure the port (it is 20446 based on your screenshot) and the JDK version of the remote process that is used to run the remote JVM is the same as set in Remote Debug Configuration. Also make sure the port is not already occupied by another process.
I have found the reason but cannot get it solved.
I use other mac as server to test, debug could connect normal. However, when I try to connect to linux server[I have tried both ubuntu 16.6 and centos7.5), connection always reset by the server. So, I cat the TCP protocol with Wireshark, I found that the debugger in IDEA not sending the normal TCP connection, which send PSH before connection was build. Here is the screen shot:
1. TCP successful connected to other mac:
2. TCP failed connect to linux server:
But I don't know how to solve this, is any one could offer help?
My IDEA version:IntelliJ IDEA 2019.1.2 (Ultimate Edition) Build #IU-191.7141.44, built on May 7, 2019
update:
use ssh proxy could solve this problem:
ssh -qTfnN -L 0.0.0.0:8094:myserver:8094 root@myserver
Verify that you are using same parameters for launching the debug and same JDK version with the linux as with the Mac.
I had the same problem, and after doing all the changes that were here exposed (and in other websites), now it work well using the port 5009 instead 5005.
(I am using mac as well)
I lauched my web app through:
gradlew appRunDebug
plugins {
id 'war'
id 'org.gretty' version '3.0.1'
}
// Tell gretty to start and stop the server on test
gretty {
integrationTestTask = 'test'
debugPort = 5009
debugSuspend = false
}
And later I used a Remote Debug inside my IntelliJ IDE:
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5009
I had a similar issue using Docker. One additional cause for the handshake exception is that your local Java Virtual Machine version is incompatible with the Docker Java Virtual Machine (image) your using.
eg: It's not possible to handshake between JDK 8 and JDK 11. However JDK 11 to JDK 8 seems to be ok.
I found once I made sure the versions were the same, handshaking worked.
Hello,
I am using vagrant on ubuntu OS,virtual box, Kubernetes and skaffold, I faced the same issue of : "Unable to open debugger port (localhost:5005): java.io.IOException "handshake failed - connection prematurally closed"
it was working fine, till the windows became 11, after that I faced all the issues, I tried to return it to 10 but with no luck
what I tried is:
1- make JDK (11.0.14) the same at vagrant and local machines.
2- JAVA_TOOL_OPTIONS=
3-
here you can find the configuration of remote debugging.
4- vagrant configuration, and there is another file called
5- forward-port.sh
6-
run this command
jdb -attach 5005
Saraham seems like the remote JVM process is not accessible via the port. Double check your network configuration, firewall (inlcuding Windows firewall/antivirus) - that they are not blocking ports and that remote interface is routable.