Closed
Description
Jetty version(s)
9.4.43.v20210629
Java version/vendor (use: java -version)
openjdk version "1.8.0_292"
OS type/version
Ubuntu 18.04 (x64)
eclipse version
4.6 neon
Description
Attempting to debug a web application using eclipse remote debugging will fail if the logging-logback module of the jetty server is enabled. The eclipse debugger will see and connect to the debug port, but no breakpoints will be hit and execution will never pause.
How to reproduce?
- Enable the logback module via the command line (java -jar ../start.jar --add-to-start=logging-logback)
- Add the dependencies to the project pom
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.6</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.6</version>
</dependency>
- Build and deploy the web app.
- Start the server with a debug port using the args '-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9999'
- Create and launch a debug configuration for a Remote Java Application with properties host:localhost and port:9999
- Wait for the debugger to connect and the suspended server startup to complete.
- Add and eclipse breakpoint in a web service method.
- Navigate to the web service via a browser.
Result: The web method will execute and return results. None of the eclipse breakpoints will be hit. If steps 3-8 are repeated with logging-logback disabled in start.ini, the breakpoints will be hit and execution will pause as expected.
Activity
joakime commentedon Dec 16, 2021
That's because on Jetty 9.x enabling non-default logging forks the JVM.
This is because enabling logging needs to be done first, as close to the start of the JVM as possible.
If you swap logging implementations, a new JVM needs to be created.
Your debug
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9999
is only impacting the initial JVM, not the forked JVM with your Jetty code.You have a few options.
Upgrade to Jetty 10 and the forked JVM isn't being done anymore.
Jetty 10 uses slf4j-api only, so there's no swap, you have to specify a logging implementation to even start once.
Embrace the forking and use the module system properly.
Add a
${jetty.base}/start.d/debug.ini
with the following content. (1 JVM argument per line)Use the
start.jar --dry-run=<parts>
to build your JVM arguments to execute without forking.See https://github.com/eclipse/jetty.project/blob/jetty-9.4.44.v20210927/jetty-start/src/main/resources/org/eclipse/jetty/start/usage.txt#L36-L54
https://github.com/eclipse/jetty.project/blob/8da83308eeca865e495e53ef315a249d63ba9332/jetty-start/src/main/resources/org/eclipse/jetty/start/usage.txt#L36-L54
pbtura commentedon Dec 16, 2021
Thank you, that makes sense. Is there a way to do the fork from the command line or from the startup script so I don't have to keep editing my start.ini every time I want to debug?
joakime commentedon Dec 16, 2021
You could create a
${jetty.base}/modules/remote-debug.mod
with the following content ...Then when you want debug just add the command line
--module=remote-debug
and it will be use for just that execution.Think of this as a non-stored configuration.
pbtura commentedon Dec 16, 2021
That is exactly what I was looking for. Thank you.
Do you think I should file an enhancement request to update the documentation? I don't see anywhere in the user guide (https://www.eclipse.org/jetty/documentation/jetty-9/index.html#advanced-debugging) that this behaviour is explicitly called out.
Issue #7299 - Enabling the logging-logback module prevents eclipse re…
sbordet commentedon Dec 23, 2021
I filed #7335 about the documentation.
@pbtura you can review the pull request to feedback whether the documentation is satisfying for you?
pbtura commentedon Dec 23, 2021
Issue #7299 - Enabling the logging-logback module prevents eclipse re…
Issue #7299 - Enabling the logging-logback module prevents eclipse re… (
Squashed commit of the following: