Remote debugging a gke pod running a java app in IntelliJ - java

I know this question has been asked a lot, however none of the answers are resolving my issue(s).
Steps I take:
I add -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8765 to the JAVA_TOOL_OPTIONS so it looks like this
- name: JAVA_TOOL_OPTIONS
value: -XX:+ExitOnOutOfMemoryError -Xms512m -Xmx1g -Xss256k -Dhttp.maxConnections=1000
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8765 -Dlogging.config=classpath:logback-kube.xml
I run kubectl port-forward [pod name] 8765:8765
I make a debug configuration in IntelliJ that looks like the following screenshot
run the debug configuration I just made.
This breaks on step 1. By breaks I mean the pod enters the CrashLoopBackOff state.
What am I missing? If I need to upload more info please let me know and I'll add it as soon as I can.
Container logs (retrieved using kubectl logs [pod name]):
Picked up JAVA_TOOL_OPTIONS: -XX:+ExitOnOutOfMemoryError -Xms512m -Xmx1g -Xss256k -Dhttp.maxConnections=1000 -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5010 -Dlogging.config=classpath:logback-kube.xml
ERROR: transport error 202: gethostbyname: unknown host
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [debugInit.c:750]

The solution was rather simple. -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8765
should be changed to
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:8765

Related

Intellij 2019.1 Gradle delegated IDE debug ended up with error

I created simple intellij Run/Debug configuration to start main class.
My idea is set to delegate build to gradle to avoid complications with annotation processors.
Im using gradle 5.4 and intellij 2019.1
When I hit debug button it ended up with this:
17:10:21: Executing task 'Main.main()'...
Connected to the target VM, address: '127.0.0.1:61876', transport: 'socket'
> Task :wrapper
BUILD SUCCESSFUL in 7s
1 actionable task: 1 executed
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the User Manual chapter on the daemon at https://docs.gradle.org/5.4/userguide/gradle_daemon.html
Process command line: C:\Program Files\Java\jdk1.8.0_201\bin\java.exe -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=61876 -Xms256m -Xmx512m -Dfile.encoding=windows-1252 -Duser.country=SK -Duser.language=sk -Duser.variant -cp C:\Users\xxx\.gradle\wrapper\dists\gradle-5.4-bin\59btlbly62hzjka9h1c4c86kd\gradle-5.4\lib\gradle-launcher-5.4.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 5.4
Please read the following process output to find out more:
-----------------------
ERROR: transport error 202: connect failed: Connection refused
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [debugInit.c:750]
Disconnected from the target VM, address: '127.0.0.1:61876', transport: 'socket'
17:10:29: Task execution finished 'Main.main()'.
I have another gradle project, also delegated to gradle and that one is working well. I cannot find out what is causing the problem.
Here's successful console output:

Spring Boot with debug args not close debug port after application stopped

I'm running my Spring Boot application with debug mode enabled. Like:
mvn -P dev spring-boot:run -Drun.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"
I can debug the application after that without any problem. But, after stopped (ctrl + c) and try to start again, I receive this error:
[INFO] Attaching agents: []
ERROR: transport error 202: bind failed: Address already in use
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [debugInit.c:750]
So, every time that I need to start the application in debug mode after that, I need to kill the process using the port 5005.
I would like to know why the port 5005 is still opened after stop the application.
I'm using Cygwin64 on Windows 10, Maven 3.5.2, Java 8 and Spring Boot 1.5.9.RELEASE.
Thanks!
This is not a problem of Spring Boot, but a problem of non-cygwin applications running in cygwin. And your application is not only leaving port 5005 open, it just keeps running in the background, having port 8080 also opened, but as on a restart the debug port is first opened, this is what you see in the error message.
This was discussed in a SpringBoot issue back in 2014 https://github.com/spring-projects/spring-boot/issues/773. I cite from this issue (the link in the citation dates from 2006):
Anyone still following this bug, this isn't a Spring Boot bug at all. It's a known problem with non-Cygwin programs (Java in this case) running on pty-based terminals.
See this link for a full explanation why this can't be fixed: http://cygwin.com/ml/cygwin/2006-12/msg00151.html
So you can basically use one of the following approaches:
use the native windows terminal and setup your java and maven environment for that
run your maven command from within an IDE which can handle this - you might use this for debugging as well
add the Spring Actuator to your app and use the /shutdown endpoint to stop your application

Intellij debugger giving error for groovy tests while running using gradle test runner but works while using java test runner [duplicate]

I am trying to debug a simple Java application on my machine using Eclipse as an IDE. When I try to debug the application by entering the Debug Perspective, I set a breakpoint and start debug. Within a few seconds, the following pop-up window:
Launching unicodeRead has encountered a problem. Cannot connect to VM.
The message dumped on the console is as follows:
ERROR: transport error 202: connect failed: Connection refused
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [../../../src/share/back/debugInit.c:708]
FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)
How do I correct this? Why does this happen?
I just had the same problem.
Yesterday everything worked fine, now nothing - same error as you gave. I found out that network admins made some changes in the meantime. Some firewall stuff. Problem is that Eclipse tries to establish connection to JVM at "localhost" (and some random port). When I tried pinging localhost (or 127.0.0.1) I got following:
C:\Windows\system32>ping 127.0.0.1
Pinging 127.0.0.1 with 32 bytes of data:
PING: transmit failed. General failure.
PING: transmit failed. General failure.
PING: transmit failed. General failure.
PING: transmit failed. General failure.
and
C:\Windows\system32>ping localhost
Ping request could not find host localhost. Please check the name and try again.
It seams that in some cases DNS is expected to resolve this, and if firewall prevents localhost requests to DNS - stuff breaks. I had to alter hosts file and remove comments in following lines, so I would not rely on DNS for this anymore:
# 127.0.0.1 localhost
# ::1 localhost
Although it is written that hosts file changes take effect immediately, I think that some processes locked this and restart was necessary in my case. After that, everything worked again.
Had same problem, but the solution was to run the application with -server=y option and not with -server=n.
Before:
java -agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:5005
After:
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=localhost:5005
Looks like the same problem as here. A reboot of the pc fixed the problem there. I haven't found any other solutions.
I was seeing an error while using the -X format:
java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=n myapp
The error went away when I switched to the newer format:
java -agentlib:jdwp=transport=dt_socket,server=y,address=4000,suspend=n myapp
Its Very Simple,Just do the Following Changes in eclipse.ini file.
-vm
binary\com.sun.java.jdk.win32.x86_1.6.0.u43\jre\bin\javaw.exe
I changed
-agentlib:jdwp=transport=dt_socket,address=9009,server=n,suspend=y
to
-agentlib:jdwp=transport=dt_socket,address=9009,server=y,suspend=n
and that did the trick!
My case is I have a bunch of domains refer to 127.0.0.1 in hosts file, like this:
127.0.0.1 localhost domian1.local domain2.local domain3.local
one day I added another new domain to refer to 127.0.0.1. By mistake, I put the domain in front of "localhost", like this:
127.0.0.1 domain4.local localhost domian1.local domain2.local domainx.local
After this, I always got an alert window in eclipse while debugging:
Cannot connect to VM
com.sun.jdi.connect.TransportTimeoutException
In console:
ERROR: transport error 202: connect failed: Connection refused
ERROR: JDWP: Failed to initialize transport via localhost:50470, trying localhost via 127.0.0.1:50470
FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)
ERROR: transport error 202: connect failed: Connection refused
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [../../../src/share/back/debugInit.c:690]
The solution is keep "localhost" at the first position all the time.
127.0.0.1 localhost domian1.local domain2.local domainx.local domain4.local
What solved for me was deleting the entire domain1 folder inside the domains folder on glassfish main folder.
Eclipse will ask you to recreate a domain and then everything works again.
In eclipse select Run tab -> Debug configuration -> Junit -> select your test name ->
Environment tab -> add variable server=y .
I was getting the same error on my ubuntu machine because of a mishap with the /etc/hosts file. I had commented out the mapping of localhost to 127.0.0.1, and to complicate matters further there was a swap file hanging around.
This was the first line of my /etc/hosts:
127.0.0.1 #localhost
Deleting the # fixed the problem, whereas rebooting understandably had not.
My cause & solution were completely different.
I think in my case it was due to the installation of JProfiler. I fixed it by uninstalling JProfiler and launching eclipse with the -clean option. I suspect that JProfiler was inserting itself in the debugger. The -clean option forces Eclipse to re-assess its plugins, so that alone might have been sufficient.
Continuing #gonadarian's answer, it seems Eclipse uses port 127.0.0.1 for debug purposes. This port is also called localhost. The way this error can be removed is by ensuring that there are no processes or services running on the above ports. The way to do this, on Linux is:
As root, enter the command:
netstat -tulpn | grep 127.0.0.1
If there are processes running on the above port, it will show up in the format:
process_id/process name.
Kill the above processes like so: kill -KILL process_id
Restart the computer for these changes to take effect. The error should no longer occur.

Tomcat starting failure due to timeout in Spring source

The issue is : i'm getting timeout errors when starting tomcat inside eclipse and it doesn't start at all in debug mode.
debug mode error :
FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)
ERROR: transport error 202: connect failed: Connection refused
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [../../../src/share/back/debugInit.c:741]
normal mode error : Server Tomcat v7.0 at localhost was unable to start within 45 seconds. If the server requires more time...
Please not that i'm starting tomcat without any application deployed.
I've checked ports and they are not used for sure.
Any idea please?
It seems your JDWP is not loading. Here in this article you can get an idea to resolve your problem. Check the answer from Jaikiran Pai in the post. He says that you must use the command line options to load your JDWP.
-agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=n
Hope this can helps you.
Try with this options:-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
The solution is to add memory to tomcat launching (Xms and Xmx VM parameters) script and increase timeout time. This way, the process will never fire a timeout.

Maven Eclipse Debug "JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)"

I'm trying to debug Maven tests in Eclipse. When I launch tests with the maven option maven.surefire.debug, I get this error :
ERROR: transport error 202: bind failed: Address already in use
FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [../../../src/share/back/debugInit.c:690]
/bin/sh: line 1: 27500 Abort trap
It is the same when I tried tu launch debug in my shell.
I tried to add the maven option forkMode=never, and I get another error with my weld artifact that I do not have without the maven.surefire.debug option :
Error loading Weld bootstrap, check that Weld is on the classpath
However, Weld is on my classpath.
Any ideas ?
To kill a process listening on a port:
This command should list processes listening on all ports:
netstat -ano
The -o option will display the process id.
If you're using a *nix system, you can refine a little further with:
netstat -ano | grep <badport>
When you have the process id, you can terminate it with:
Windows:
Open Task Manager, add the PID column with View > Select Columns > PID
Find the process and right-click to kill it
Others:
kill <PID>
For Mac users:
Usually the problem is that another process keeps Maven debug port 5005 open.
So I checked which process keeps this port open by executing:
lsof -i tcp:5005
The output was:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 9089 my_user 7u IPv4 0xe88ec542fd4cffc9 0t0 TCP *:avt-profile-2 (LISTEN)
And then I killed the process:
kill -9 9089
If you want these 2 process to be able to run together, you'll have to change the Maven debug port of at least one of them.
See: http://maven.apache.org/surefire/maven-surefire-plugin/examples/debugging.html.
Go to Debug configuration -> Remote Java Application -> Connect tab, check Allow termination of remote JVM.
Then, when you are going to restart the server/maven, go to Debug perspective and click the read / stop button.....
There is a long time the question was asked but i had the same problem recently.
Open Task Manager
Kill all "java.exe" process
Relaunch the mvn debug
Hope it will help
Just for documentation, I had the exact same error, running on my local:
ERROR: transport error 202: bind failed: Address already in use
FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
in my case the port wasn't the issue, but the host file. The solution is to add/re-add/uncomment:
127.0.0.1 localhost
The config file sets localhost as default, so a solution is add that host or change it for a custom one.
To add on.. I had the similar issue last week, when debugging using eclipse was made impossible.
FATAL ERROR in native method: JDWP No transports initialized,
jvmtiError=AGENT_ERROR_TRANSPORT_LOAD(196)
ERROR: transport library not found: dt_socket
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_LOAD(509)
JDWP exit error AGENT_ERROR_TRANSPORT_LOAD(196): No transports initialized [../../../src/share/back/debugInit.c:690]
Sadly non of the solution I can possibly find online was helpful.
The issue turned out to be that somehow firewall removed all the dlls in my JRE bin... (so dt_socket.dll went completely missing).
Reinstalling the entire JRE helped.
The solution to me was removing the breakpoints of project! If you have many branches and changed recently sometimes eclipse lost some's breakpoints.
first of all remove all debug points in eclipse
search for PID with server port
netstat -ano|find /i "7001"
replace 7001 with your port number in above line
sample o/p
C:\Users\shaithal>netstat -ano|find /i "7001"
TCP 127.0.0.1:51340 127.0.0.1:7001 SYN_SENT 17396
then kill that process
taskkill /F /PID 17396
search for PID with debug port also
netstat -ano|find /i "8453"
8453 is debug port in my case replace 8453 with your port number in above line
sample o/p
C:\Users\shaithal>netstat -ano|find /i "8453"
TCP 0.0.0.0:8453 0.0.0.0:0 LISTENING 19904
then kill that process
taskkill /F /PID 19904

Categories