Remote debugging a vagrant VM
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:
- 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)
- I have verified that the process is indeed listening on port 5005 on the VM. `netstat` shows that the process is listening on 5005.
- 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.
- I can connect to the remote process from the host machine via `nc localhost 5005`.
Any thoughts on what I might be missing?
请先登录再写评论。
Can you connect with `jdb -attach localhost:5005`?
No, when I do that I see the following stack trace
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.
I see, thank you!
Another possible reason is if port 5005 is already taken by some other service on the host OS. Try using some other port number.
I posted the solution at https://stackoverflow.com/a/76815037/104891.