0

I'm using vagrant on Ubuntu OS 18.04, virtual box, Kubernetes,Gradle, 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=

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

3-

here you can find the configuration of remote debugging. Debug

4- vagrant configuration, and there is another file called

Vagrant.configure("2") do |config|
  config.vm.provider "virtualbox"
  config.vm.provision :shell, path: "./forward-port.sh", run: 'always'

config.vm.define :skaffold do |skaffold|
  skaffold.vm.box = "bento/ubuntu-18.04"
  skaffold.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
  skaffold.vm.network "forwarded_port", guest: 443, host: 8443, host_ip: "127.0.0.1"
  skaffold.vm.network "forwarded_port", guest: 5005, host: 5005, host_ip: "127.0.0.1"
  skaffold.vm.network "forwarded_port", guest: 5006, host: 5006, host_ip: "127.0.0.1"
  skaffold.vm.network "forwarded_port", guest: 5007, host: 5007, host_ip: "127.0.0.1"
  skaffold.vm.network "forwarded_port", guest: 5008, host: 5008, host_ip: "127.0.0.1"
  skaffold.vm.network "forwarded_port", guest: 5009, host: 5009, host_ip: "127.0.0.1"

5- forward-port.sh

#!/bin/bash
#sudo iptables -t nat -I PREROUTING -p tcp --dport 3306 -j DNAT --to-destination 127.0.0.1:3306
#sudo iptables -t nat -I PREROUTING -p tcp --dport 6379 -j DNAT --to-destination 127.0.0.1:6379

sudo iptables -t nat -I PREROUTING -p tcp --dport 5005 -j DNAT --to-destination 127.0.0.1:5005
sudo iptables -t nat -I PREROUTING -p tcp --dport 5006 -j DNAT --to-destination 127.0.0.1:5006
sudo iptables -t nat -I PREROUTING -p tcp --dport 5007 -j DNAT --to-destination 127.0.0.1:5007
sudo iptables -t nat -I PREROUTING -p tcp --dport 5008 -j DNAT --to-destination 127.0.0.1:5008
sudo iptables -t nat -I PREROUTING -p tcp --dport 5009 -j DNAT --to-destination 127.0.0.1:5009
sudo iptables -t nat -I PREROUTING -p tcp --dport 5010 -j DNAT --to-destination 127.0.0.1:5010

6- run this command jdb -attach 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.
➜  ~ lsof -i tcp:5007
COMMAND   PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
kubectl 29967 vagrant   10u  IPv4 532332      0t0  TCP localhost:5007 (LISTEN)
kubectl 29967 vagrant   11u  IPv6 532333      0t0  TCP localhost:5007 (LISTEN)
➜  ~ lsof -i tcp:5006
COMMAND   PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
kubectl 29884 vagrant   10u  IPv4 533358      0t0  TCP localhost:5006 (LISTEN)
kubectl 29884 vagrant   11u  IPv6 533359      0t0  TCP localhost:5006 (LISTEN)
➜  ~ lsof -i tcp:5005
COMMAND   PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
kubectl 29052 vagrant   10u  IPv4 523761      0t0  TCP localhost:5005 (LISTEN)
kubectl 29052 vagrant   11u  IPv6 523762      0t0  TCP localhost:5005 (LISTEN)
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
Sara Othman
  • 11
  • 1
  • 3
  • Since `jdb -attach 5005` fails from the command line the problem might be related to the network configuration between host and VM. Try suggestions from https://stackoverflow.com/questions/62943487/intellij-debug-docker-container-keeps-giving-me-io-exception-handshake-failed. – Egor Klepikov Feb 07 '22 at 09:16
  • Also, here is a related ticket in the JetBrains bug tracker https://youtrack.jetbrains.com/issue/IDEA-173607. Feel free to vote/comment. – Egor Klepikov Feb 07 '22 at 09:18

0 Answers0