Debug remote WildFly on Linux from Windows machine

371 Views Asked by At

UPDATE

I have troubles with debugging remote WildFly application on Linux (RedHat 7.9) server. My IDE Intellij Idea 2020.1 works under Windows 10.

On Linux server:

openjdk version "1.8.0_282"
OpenJDK Runtime Environment (build 1.8.0_282-b08)
OpenJDK 64-Bit Server VM (build 25.282-b08, mixed mode)

On Windows client machine:

openjdk version "1.8.0_282"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_282-b08)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.282-b08, mixed mode)

I start WildFly with --debug option. It forces jvm to start WF with these options:

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

Then I see that debug port 8787 is ok and listens:

netstat -ln | grep 87
tcp 0 0 0.0.0.0:8787 0.0.0.0:* LISTEN

I can connect to this machine from other Linux server with jdb and everything works fine:

jdb -attach 10.20.20.40:8787
Initializing jdb ...

But when I try to connect to debug port from my Windows workstation with Idea - connection fails. And with netstat on server I see that debug port is listening to my client machine. So the attempt of connecting from Win to Linux debug port causes to fail client side connection. But on server side port remains connected. And I have to restart WildFly to open debug port again.

The same thing happens when I try to connect using jdb from windows machine.

Here shared memory transport won`t work at all.

jdb -attach 10.20.20.40:8787
java.io.IOException: shmemBase_attach failed: The system cannot find the file specified at com.sun.tools.jdi.SharedMemoryTransportService.attach0(Native Method) at com.sun.tools.jdi.SharedMemoryTransportService.attach(SharedMemoryTransportService.java:108) at com.sun.tools.jdi.GenericAttachingConnector.attach(GenericAttachingConnector.java:116) at com.sun.tools.jdi.SharedMemoryAttachingConnector.attach(SharedMemoryAttachingConnector.java:63) at com.sun.tools.example.debug.tty.VMConnection.attachTarget(VMConnection.java:519) at com.sun.tools.example.debug.tty.VMConnection.open(VMConnection.java:328) at com.sun.tools.example.debug.tty.Env.init(Env.java:63) at com.sun.tools.example.debug.tty.TTY.main(TTY.java:1083)
Fatal error: Unable to attach to target VM.

So we should try to use sockets.

jdb -connect com.sun.jdi.SocketAttach:hostname=10.20.20.40,port=8787

For now everything looking good.

Netstat on linux server showing ESTABILISHED state:

sudo netstat -nlp -a | grep 8787
tcp 0 644 10.20.20.40:8787 10.20.30.51:5344 ESTABLISHED 15480/java

On win client at the same time i see that connection estabilished:

netstat -a | findstr 5344
TCP 10.20.30.51:5344 10.20.20.40:8787 ESTABLISHED

Wait for several seconds, and then:

Internal exception: com.sun.jdi.VMDisconnectedException at com.sun.tools.jdi.TargetVM.waitForReply(TargetVM.java:307) at com.sun.tools.jdi.VirtualMachineImpl.waitForTargetReply(VirtualMachineImpl.java:1030) at com.sun.tools.jdi.PacketStream.waitForReply(PacketStream.java:69) at com.sun.tools.jdi.JDWP$EventRequest$Set.waitForReply(JDWP.java:6910) at com.sun.tools.jdi.JDWP$EventRequest$Set.process(JDWP.java:6875) at com.sun.tools.jdi.EventRequestManagerImpl$EventRequestImpl.set(EventRequestManagerImpl.java:201) at com.sun.tools.jdi.EventRequestManagerImpl$EventRequestImpl.setEnabled(EventRequestManagerImpl.java:166) at com.sun.tools.jdi.EventRequestManagerImpl$EventRequestImpl.enable(EventRequestManagerImpl.java:151) at com.sun.tools.example.debug.tty.EventRequestSpec.resolveEagerly(EventRequestSpec.java:139) at com.sun.tools.example.debug.tty.EventRequestSpecList.addEagerlyResolve(EventRequestSpecList.java:98) at com.sun.tools.example.debug.tty.Commands.resolveNow(Commands.java:1125) at com.sun.tools.example.debug.tty.Commands.commandCatchException(Commands.java:810) at com.sun.tools.example.debug.tty.VMConnection.setEventRequests(VMConnection.java:427) at com.sun.tools.example.debug.tty.VMConnection.open(VMConnection.java:337) at com.sun.tools.example.debug.tty.Env.init(Env.java:63) at com.sun.tools.example.debug.tty.TTY.main(TTY.java:1083)

Server port state remains established untill service restart:

sudo netstat -nlp -a | grep 8787
tcp 0 644 10.20.20.40:8787 10.20.30.51:5344 ESTABLISHED 15480/java

But client side is disconnected

netstat -a | findstr 5344

So is it possible to debug wildfly or java at all on Linux with Windows IDE?
Why client side debug session could close after connection attempt?
Is there some timeout settings for jdb sockets?

0

There are 0 best solutions below