-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deadlock in Jetty using Logback #8354
Comments
Also reproduced on Jetty 10.0.10, but cannot reproduce on 10.0.9 |
Is there a reason you are using an old logback? For Jetty 10 and Jetty 11 we use Logback 1.3.0 series. |
The class named There should be the same behavior between 10.0.10 and 10.0.9. |
@joakime Logback 1.2.* is not abandoned and in fact is being developing in parallel with 1.3.* Migration to the latest version is not an option right now due to dependencies issues (e.g. 1.3.* has the Jakarta API in transitive dependencies). |
Lets look at the history of this lock in July 29, 2022 (Today) Last seen in Jetty 10.0.11 The current June 16, 2021 Last seen in Jetty 10.0.5 This is what it looked like before the class was renamed in Jetty 10.0.6. The rename of July 27, 2020 Last seen in Jetty 10.0.0 August 8, 2017 Last seen in Jetty 10.0.0-alpha This was a change in commit a105be9 March 31, 2017 Last seen in Jetty 9.4.6 When the class was first created in commit f06c7c3 |
That jakarta dependency might look scary at first, but follow the trail ... This references This references Servlet 5.0 is part of the Jakarta EE9 effort which had namespace changes from The logback-core has no actual direct usage of servlet. But servlet is still optional for logback, not mandatory. If you use logback-access, then note that logback-access has other issues, so don't use it (any version of logback-access) until they fix the open bugs with it. logback-access bugs: Jetty bugs about logback-access:
We are heavy users of logback ourselves, in fact we prefer it over log4j2 and alternatives, and have not experienced this deadlock issue ourselves, even during extreme load testing (think saturated multi gigabit network interfaces during testing). A deadlock would definitely be noticed. Have you considered that this deadlock could be due to a specific configuration quirk on your logback setup/configuration? |
This is a simple enough change, I can make it. Ideally, a testcase that can replicate this is an important first step. |
…eExecutionStrategy Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
When we break down your threaddump, we see ...
The lock created by |
This class doesn't contain any I agree that our setup may be not the most common one since we use the custom Logback appender and the custom Jetty connector. But we don't use any Jetty hacks just documented API and there is the proof that the deadlock can be formally reproduced. Just the idea: maybe the ReadWriteLock will work better for |
Sorry but the logging framework should deal with these issues, as The problem is the lock on the If that is out of your control because it's performed by the Logback implementation, then it's a bug in Logback. From your description, I bet you can reproduce this bug without any dependency on Jetty, just by implementing a |
@sbordet A servlet container as a universal tool is expected to be able to correctly work in different environments. In this scenario, one of the critical classes from Jetty internals leaks its reference into third-party SLF4J API implementation. This implementation is out of control and can acquire the exclusive lock at any time and interrupt normal server behavior. It's a common practice to pass |
@alekkol the same Jetty code with another logging library that is not Logback does not have any problem, because the other logging libraries do not have the Logback bug. It is not a Jetty issue. Try, and you will be able to reproduce the bug using Logback without any Jetty dependency. |
@sbordet Of course, it can be reproduced with the Logback library only. But the same is true for the opposite: we have been using this logger for years and never had the same issues before. It appeared only after migrating to Jetty from another servlet container. |
The lock in We are not the only ones grabbing a lock in You agree that you are using a buggy logging library. File an issue there, or change the buggy library you are using. |
That's why this issue was created. Both Jetty and Logback have the same bug - they call alien methods under the exclusive lock section provoking deadlocks. Jetty does it in
This example is not relevant since |
You have created it in the wrong project. It is not a Jetty issue. And we are not calling alien methods. If we start implementing workarounds in Jetty for other libraries bugs, we would not have time to do any work on Jetty. |
Why "calling a logging API (SLF4J)" in a critical section in Jetty is not a bug but calling
It's a workaround for the Jetty bug. And it should be pretty easy to make this error happen rarely or even never by just removing Jetty critical classes references leakage into external API. |
Not a Jetty issue. |
Guess somethimes my app is having somethig similar after Jetty version up, I'm trying to investigate if it is related. @alekkol It seems the two locks are always being "logically" nested, because Correct me if I'm wrong, the order of key events is:
What is logically the possible scenario of Dead lock? |
@diziaq that logic is a red herring, the problem has nothing to do with the In this specific case (of the original issue) the custom appender ( The original issue's See:
They could have chosen |
While Logback does seemingly have its issues, I don't think I like Jetty maintainers responses here.
|
The "fix" of jetty not logging with locks held is not a fix, as it makes those logs non deterministic and thus not useful. If you don't want those logs then turn off that logger. |
Jetty version(s)
Jetty 10.0.11
Logback 1.2.11
Java version/vendor
openjdk version "17.0.3" 2022-04-19
OpenJDK Runtime Environment Temurin-17.0.3+7 (build 17.0.3+7)
OpenJDK 64-Bit Server VM Temurin-17.0.3+7 (build 17.0.3+7, mixed mode)
OS type/version
Initially reproduced in GitHub Actions on the
ubuntu-latest
runnerAlso reproduced locally on OSX 12.2
Description
org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy
uses internalAutoLock
instance to synchronize access to mutable state, this lock is acquired on eachtoString()
call. Logback library internals contains synchronized methodch.qos.logback.core.AppenderBase.doAppend()
which is invoked for every logging event.The following situation causes deadlock and full application outage due to blocked logging:
Thread 1:
Thread 2:
Thread dump with the issue:
The text was updated successfully, but these errors were encountered: