Skip to content

Enabling the logging-logback module prevents eclipse remote debugging #7299

Closed
@pbtura

Description

@pbtura

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?

  1. Enable the logback module via the command line (java -jar ../start.jar --add-to-start=logging-logback)
  2. 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>
  1. Build and deploy the web app.
  2. Start the server with a debug port using the args '-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9999'
  3. Create and launch a debug configuration for a Remote Java Application with properties host:localhost and port:9999
  4. Wait for the debugger to connect and the suspended server startup to complete.
  5. Add and eclipse breakpoint in a web service method.
  6. 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

added
BugFor general bugs on Jetty side
on Dec 16, 2021
joakime

joakime commented on Dec 16, 2021

@joakime
Contributor

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.

  1. 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.

  2. 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)

    --exec
    -Xdebug
    -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9999
    
  3. 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

pbtura commented on Dec 16, 2021

@pbtura
Author

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

joakime commented on Dec 16, 2021

@joakime
Contributor

You could create a ${jetty.base}/modules/remote-debug.mod with the following content ...

[exec]
-Xdebug
-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9999

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

pbtura commented on Dec 16, 2021

@pbtura
Author

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.

added and removed
BugFor general bugs on Jetty side
on Dec 16, 2021
self-assigned this
on Dec 16, 2021
added a commit that references this issue on Dec 23, 2021

Issue #7299 - Enabling the logging-logback module prevents eclipse re…

70df522
sbordet

sbordet commented on Dec 23, 2021

@sbordet
Contributor

I filed #7335 about the documentation.
@pbtura you can review the pull request to feedback whether the documentation is satisfying for you?

pbtura

pbtura commented on Dec 23, 2021

@pbtura
Author
added a commit that references this issue on Jan 3, 2022

Issue #7299 - Enabling the logging-logback module prevents eclipse re…

169f759
added a commit that references this issue on Jan 3, 2022

Issue #7299 - Enabling the logging-logback module prevents eclipse re… (

528ac64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @joakime@sbordet@pbtura

    Issue actions

      Enabling the logging-logback module prevents eclipse remote debugging · Issue #7299 · jetty/jetty.project