Open hd42 opened 5 months ago
@hd42, this sounds like a deadlock to me. That is, ProviderUtil
is trying to acquire the initialization lock that is already acquired. We can improve the diagnostics by reporting if there is already an on-going initialization, but that will only point the problem, not solve it. Could you share a complete thread dump?
threaddump2.txt Yes, that's what I figured. I'll try to attach a debugger and see when the initialization is called.
@hd42,
What kind of application are you developing? It seems you are writing an RCP or an OSGi application? If so, what kind and version of OSGi framework you are using?
Yes, I am developing an Eclipse Plugin, so the OSGi framework is the one bundled with Eclipse 2024-03.
As far as I can see, org.apache.logging.log4j.util.Activator#unlockIfReady() is called a lot but never enters the if block because ProviderUtil.PROVIDERS remains empty.
This seems related to the order of activation of the OSGi bundles: the LogManager
class initialization will block until the log4j-core
bundle is started. Log4j does not have an OSGi-friendly mechanism to switch logging backends.
You should make sure the log4j-core
starts before your Eclipse plugin, but I don't have too much familiarity with OSGi frameworks. @HannesWell, any idea?
I see Activator#start gets called but doesn't find any bundle that contains a provider. I don't see log4j-core installed in the plugins. log4j seems to block itself from working without providers - I would have assumed a default implementation or an error message instead. So I'll look into the installations that do work to see which bundle installed there includes a log4j provider and install that plugin in my Eclipse.
log4j-core
, log4j-to-slf4j
and log4j-to-jul
are Log4j API providers.
There is a simple provider embedded in log4j-api
, but typically that is not what you want to use. Since Logger
implementations are usually static fields, the API waits for the "definitive" provider to come online, before it returns a Logger
.
I debugged a working installation and was surprised to see that it didn't ever call Activator#start. The first call was to ProviderUtil#lazyInit(), which unlocks even with empty PROVIDERS.
So now I need to figure out, why some installations call the Activator and others don't. Both have no provider installed, so maybe I'll try installing one to not have to worry about Log4J waiting forever.
Adding log4j-to-slf4j has fixed my problem as far as I can see. Thank you for your help.
An indefinite wait still seems problematic to me, so maybe you should throw an "No Providers Configured" exception after a timeout.
Description
I am using an Eclipse plugin that uses Apache POI, which in turn uses Log4j. It runs fine in most configurations, but in some constellations I haven't been able to conclusively pin down (installed the same version twice, one works, the other reproducibly blocks), the UI hangs indefinitely. I took thread dumps in multiple occasions and the main thread always is parked inside ProviderUtil.lazyInit. What could be the cause of this?
Configuration
Version: 2.23.1
Operating system: Windows 10
JDK: different versions, including JustJ (17.0.10) and Temurin (21.0.3)
Logs