Skip to content

Commit

Permalink
Prevent possible deadlock (#5830)
Browse files Browse the repository at this point in the history
  • Loading branch information
trask committed Apr 14, 2022
1 parent 1f9c1c1 commit 4879ced
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
Expand Down Expand Up @@ -264,14 +265,18 @@ private static void runAfterAgentListeners(
// to touch it due to classloader locking.
boolean shouldForceSynchronousAgentListenersCalls =
Config.get().getBoolean(FORCE_SYNCHRONOUS_AGENT_LISTENERS_CONFIG, false);
if (!shouldForceSynchronousAgentListenersCalls
&& isJavaBefore9()
&& isAppUsingCustomLogManager()) {
boolean javaBefore9 = isJavaBefore9();
if (!shouldForceSynchronousAgentListenersCalls && javaBefore9 && isAppUsingCustomLogManager()) {
logger.fine("Custom JUL LogManager detected: delaying AgentListener#afterAgent() calls");
registerClassLoadCallback(
"java.util.logging.LogManager",
new DelayedAfterAgentCallback(config, agentListeners, autoConfiguredSdk));
} else {
if (javaBefore9) {
// force LogManager to be initialized while we are single-threaded, because if we wait,
// LogManager initialization can cause a deadlock in Java 8 if done by two different threads
LogManager.getLogManager();
}
for (AgentListener agentListener : agentListeners) {
agentListener.afterAgent(config, autoConfiguredSdk);
}
Expand Down

0 comments on commit 4879ced

Please sign in to comment.