title: "Unable to open debugger port (localhost:5005): java.io.IOException "handshake failed - connection prematurally closed"
body: <p>I'm using vagrant on Ubuntu OS 18.04, virtual box, Kubernetes,Gradle, and skaffold, I faced the same issue of: &quot;Unable to open debugger port (localhost:5005): java.io.IOException &quot;handshake failed - connection prematurally closed&quot;</p>
  <p>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</p>
  <p>What I tried is:</p>
  <p>1- make JDK (11.0.14) the same at vagrant and local machines.</p>
  <p>2- JAVA_TOOL_OPTIONS=</p>
  <pre><code>&quot;-agentlib:jdwp=transport=dt_socket,server=y,address=*:5005,suspend=n&quot;
  </code></pre>
  <p>3-</p>
  <p>here you can find the configuration of remote debugging.
  <a href="https://i.stack.imgur.com/bDnGl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bDnGl.png" alt="Debug" /></a></p>
  <p>4- vagrant configuration, and there is another file called</p>
  <pre><code>Vagrant.configure(&quot;2&quot;) do |config|
    config.vm.provider &quot;virtualbox&quot;
    config.vm.provision :shell, path: &quot;./forward-port.sh&quot;, run: 'always'
  
  </code></pre>
  <pre><code>config.vm.define :skaffold do |skaffold|
    skaffold.vm.box = &quot;bento/ubuntu-18.04&quot;
    skaffold.vm.network &quot;forwarded_port&quot;, guest: 80, host: 8080, host_ip: &quot;127.0.0.1&quot;
    skaffold.vm.network &quot;forwarded_port&quot;, guest: 443, host: 8443, host_ip: &quot;127.0.0.1&quot;
    skaffold.vm.network &quot;forwarded_port&quot;, guest: 5005, host: 5005, host_ip: &quot;127.0.0.1&quot;
    skaffold.vm.network &quot;forwarded_port&quot;, guest: 5006, host: 5006, host_ip: &quot;127.0.0.1&quot;
    skaffold.vm.network &quot;forwarded_port&quot;, guest: 5007, host: 5007, host_ip: &quot;127.0.0.1&quot;
    skaffold.vm.network &quot;forwarded_port&quot;, guest: 5008, host: 5008, host_ip: &quot;127.0.0.1&quot;
    skaffold.vm.network &quot;forwarded_port&quot;, guest: 5009, host: 5009, host_ip: &quot;127.0.0.1&quot;
  </code></pre>
  <p>5- forward-port.sh</p>
  <pre><code>#!/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
  </code></pre>
  <p>6- run this command <code>jdb -attach 5005</code></p>
  <pre><code>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.
  </code></pre>
  <pre><code>➜  ~ 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)
  </code></pre>