Remote debugging: No connection to Wildfly 14 on O

2020-03-09 07:32发布

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.

3条回答
混吃等死
2楼-- · 2020-03-09 07:45

For jdk 11,you should use

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

instead.

查看更多
别忘想泡老子
3楼-- · 2020-03-09 07:56

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.

查看更多
Anthone
4楼-- · 2020-03-09 07:59

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.

查看更多
登录 后发表回答