24

I'm trying to connect my debugger to Wildlfy running on Open JDK 11.

Despite Wildfly says:

Listening for transport dt_socket at address: 8787

My IDE (IntelliJ IDEA CE 2018.1) claims that it doesn't get any connection:

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

I'm starting Wildfly via standalone.sh --debug resulting in the following JAVA_OPTS:

-server
-Xms64m
-Xmx512m
-XX:MetaspaceSize=96M
-XX:MaxMetaspaceSize=256m
-Djava.net.preferIPv4Stack=true
-Djboss.modules.system.pkgs=org.jboss.byteman
-Djava.awt.headless=true
-agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=n
--add-exports=java.base/sun.nio.ch=ALL-UNNAMED
--add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED
--add-exports=jdk.unsupported/sun.reflect=ALL-UNNAMED
--add-modules=java.se

Did something change in Java 9/10/11? Remote debugging with the exact same setup works fine when using Oracle JDK 8.

Using telnet I can confirm, that port 8787 is indeed not reachable.

Update after reading @ehsavoie's comment: netstat -ln on the server running Wildfly shows:

Proto Recv-Q Send-Q Local Address           Foreign Address         State   
tcp        0      0 127.0.0.1:8787          0.0.0.0:*               LISTEN 

So apparently with OpenJDK 11 the debug port is now bound to localhost by default.

Mikhail Kholodkov
  • 23,642
  • 17
  • 61
  • 78
Sebastian S
  • 4,420
  • 4
  • 34
  • 63
  • Few doubts in general - Does that work on any other port by the way? What is the content of `standalone.sh`? How about tracing any failure logs for this? – Naman Nov 08 '18 at 03:17
  • `standalone.sh` is the [unpatched file from Wildfly 14.0.1](https://github.com/wildfly/wildfly-core/blob/6.0.2.Final/core-feature-pack/src/main/resources/content/bin/standalone.sh). Like what other ports? Wildfly is reachable via 8080, 8443 and 9990. 8787 is clearly exposed as debug port in the aforementioned JAVA_OPTS. – Sebastian S Nov 08 '18 at 07:39
  • 1
    and if you set suspend to yes (y) does the startup suspend ? Just checking that the debug option is taken into account by the JVM – ehsavoie Nov 08 '18 at 08:04
  • @ehsavoie indeed Wildfly suspends after logging `Listening for transport dt_socket at address: 8787`. However my IDE (IntelliJ Idea) still says `Unable to open debugger port (localhost:8787): java.io.IOException "handshake failed - connection prematurally closed"` – Sebastian S Nov 08 '18 at 09:00
  • 1
    What does netstat -ln show ? – ehsavoie Nov 08 '18 at 14:32
  • @ehsavoie that was the important hint. According to netstat the debug port was bound to `127.0.0.1:8787` instead of `0.0.0.0:8787`. Apparently this changed with one of the latest Java releases. I'd accept this as an answer if you want to write one. Starting Wildfly with `standalone.sh --debug 0.0.0.0:8787` solves it. – Sebastian S Nov 08 '18 at 14:48

3 Answers3

38

For jdk 11,you should use

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

instead.

white.black
  • 381
  • 2
  • 3
  • Seems like in java8 address could just be port and by java11 address means address and port for systems with multiple interface, I presume. Thanks for this. – Peter Kahn Nov 26 '19 at 14:31
31

The cause lies in the default behaviour that changed with Java 9 according to this answer: Beginning with Java 9, the JVM only accepts local connections unless otherwise specified.

Therefore the solution is fairly easy:

While with Java 8 it is sufficient to start Wildfly with --debug, with Java 9 I needed to change this to --debug *:8787.

Sebastian S
  • 4,420
  • 4
  • 34
  • 63
1

In my case, I was using Java 8 in my machine, but the remote Wildfly instance was running on Java 11.

When I changed my Java version to 11, it worked.

brunobastosg
  • 1,380
  • 19
  • 31