Remote debugging a vagrant VM

Answered

I'm running IntelliJ IDEA 2023.1.2 (Community Edition) and I'm having a problem remotely debugging a java application running on a vagrant VM. My vagrant VM is running Ubuntu 20.04.

The problem is that when I run the remote debugger, I see the following error in intellij

Unable to open debugger port (localhost:5005): java.net.SocketException "Connection reset"

Additionally, the syslog on the vagrant VM shows the following after one of these failed connections

Aug 01 19:14:43 ubuntu2004.localdomain sshd[2095]: debug3: channel 0: waiting for connection
Aug 01 19:14:43 ubuntu2004.localdomain sshd[2095]: debug1: channel 0: connection failed: Connection refused
Aug 01 19:14:43 ubuntu2004.localdomain sshd[2095]: error: connect_to 192.168.121.118 port 5005: failed.

Here are some observations:

  1. The java application which is running on the VM has debugging enabled (i.e., it includes `java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005` in the process)
  2. I have verified that the process is indeed listening on port 5005 on the VM. `netstat` shows that the process is listening on 5005.
  3. I have forwarded the port to my host machine's port 5005, and can see on the host machine that the port forwarding is enabled.
  4. I can connect to the remote process from the host machine via `nc localhost 5005`.

Any thoughts on what I might be missing?

0
6 comments

Can you connect with `jdb -attach localhost:5005`?

0

No, when I do that I see the following stack trace

$> jdb -attach localhost:5005
java.io.IOException: handshake failed - connection prematurally closed
at jdk.jdi/com.sun.tools.jdi.SocketTransportService.handshake(SocketTransportService.java:142)
at jdk.jdi/com.sun.tools.jdi.SocketTransportService.attach(SocketTransportService.java:255)
at jdk.jdi/com.sun.tools.jdi.GenericAttachingConnector.attach(GenericAttachingConnector.java:119)
at jdk.jdi/com.sun.tools.jdi.SocketAttachingConnector.attach(SocketAttachingConnector.java:83)
at jdk.jdi/com.sun.tools.example.debug.tty.VMConnection.attachTarget(VMConnection.java:519)
at jdk.jdi/com.sun.tools.example.debug.tty.VMConnection.open(VMConnection.java:328)
at jdk.jdi/com.sun.tools.example.debug.tty.Env.init(Env.java:63)
at jdk.jdi/com.sun.tools.example.debug.tty.TTY.main(TTY.java:1095)
 
Fatal error:
Unable to attach to target VM.
0

So, it's a networking issue that is not related to IntelliJ IDEA. You can ask for help at https://stackoverflow.com/.

See also https://foojay.io/today/jdb/.

With the recent Java versions you should use address=*:5005 to bind to the wildcard address as the port forward to VM may not work for the localhost interface.

1

I see, thank you!

0

Another possible reason is if port 5005 is already taken by some other service on the host OS. Try using some other port number.

1

Please sign in to leave a comment.