Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handshake failed - connection prematurally closed error when debugging Solr in Intellij

So i was going to debug my Solr filter plugins on Intellij Community Edition. After i ran the program from comand prompt with this command

java -jar start.jar -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8983

I started my Intellij debugger with this config:

Transport : socket
Debugger mode : attach
Host : localhost
Port : 8983

But when I ran the debugger I got this error:

Error running Debugger: Unable to open debugger port (localhost:8983): 
java.io.IOException "handshake failed - connection prematurally closed"

Any idea how to fix this?

like image 479
donthurtme Avatar asked Oct 06 '22 15:10

donthurtme


People also ask

Why debug is not working in Intellij?

To solve this, simply remove the jar of the debugged module from all modules' dependencies in the Project Structure. If you do not know which modules have the debugged module jar as dependencies, you can use some tools (Eg. Sublime Text, bash, ...) to search for the module name which is stored in Intellij *.

What is the debug port for Tomcat?

By default tomcat running port is 8080. So for the debugger, I will allocate port 8081. For that, you can select any port except tomcat running port or any other allocated ports in your localhost for other running servers.


2 Answers

I got that error when trying to access to debug port on a Docker container.

If you are trying to access the debug port inside a Docker container make sure you are specifying the port as *:5005

E.g.

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

This has been changes since Java 9.

See: REGRESSION: Remote debugging does not work on JDK 9

It's not a bug. It's a security.

Before the JDK-8041435

If you have a server with EXT and INT interfaces and start Java process with address=5900 it binds to both interfaces and allow anybody from entire world to connect to your java process unless you block it on firewall.

After JDK-8041435 socket transport try to guess localhost and bind to localhost only. I.e. socket transport by default works only if both client and server are located on the same machine. It's not an easy task to guess proper localhost. so ever same-machine configuration might not work in some situation because of network setup.

You can restore old, insecure behavior using * (asteric) i.e. -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5900 should work exactly as it was before JDK-8041435

But it's recommended to explicitly specify ip address to bind when it possible.

And JDWP socket connector accept only local connections by default

The JDWP socket connector has been changed to bind to localhost only if no ip address or hostname is specified on the agent command line. A hostname of asterisk (*) may be used to achieve the old behavior which is to bind the JDWP socket connector to all available interfaces; this is not secure and not recommended.

like image 67
brass monkey Avatar answered Oct 17 '22 18:10

brass monkey


It should be something like this,

java "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8983" -jar start.jar

it's working now

like image 20
donthurtme Avatar answered Oct 17 '22 17:10

donthurtme