Dherik
Dherik

Reputation: 19110

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!

Upvotes: 2

Views: 1743

Answers (1)

Abacus
Abacus

Reputation: 19471

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:

  1. use the native windows terminal and setup your java and maven environment for that
  2. run your maven command from within an IDE which can handle this - you might use this for debugging as well
  3. add the Spring Actuator to your app and use the /shutdown endpoint to stop your application

Upvotes: 1

Related Questions