This is an automated email from the ASF dual-hosted git repository.

lujiajing pushed a commit to branch fix-discussion-12572
in repository https://gitbox.apache.org/repos/asf/skywalking-java.git

commit d16ca58a80a893d93f38def927ce1994d3700bae
Author: Megrez Lu <lujiajing1...@gmail.com>
AuthorDate: Mon Sep 23 11:37:17 2024 +0800

    fix ClassCircularityError
    
    Signed-off-by: Megrez Lu <lujiajing1...@gmail.com>
---
 CHANGES.md                                         |  2 +-
 .../skywalking/apm/agent/SkyWalkingAgent.java      | 51 +++++++++++++++-------
 dist-material/LICENSE                              |  2 +-
 pom.xml                                            |  2 +-
 4 files changed, 38 insertions(+), 19 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index f2534d9be3..6065dc9f9b 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -7,7 +7,7 @@ Release Notes.
 
 * Upgrade nats plugin to support 2.16.5
 * Add agent self-observability.
-
+* Update ByteBuddy to 1.15.1 and resolve the ClassCircularityError.
 
 All issues and pull requests are 
[here](https://github.com/apache/skywalking/milestone/222?closed=1)
 
diff --git 
a/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java
 
b/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java
index 2dd3fe8b38..eab26e92f3 100644
--- 
a/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java
+++ 
b/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java
@@ -69,6 +69,25 @@ import static 
org.apache.skywalking.apm.agent.core.conf.Constants.NAME_TRAIT;
 public class SkyWalkingAgent {
     private static ILog LOGGER = LogManager.getLogger(SkyWalkingAgent.class);
 
+    static {
+        circularityErrorWorkaround();
+    }
+
+    /**
+     * <a href="https://github.com/DataDog/dd-trace-java/pull/4865";>Follow the 
idea from dd-trace-java</a> to resolve
+     * the ClassCircularityError introduced in ByteBuddy >= 1.12.11.
+     *
+     * @see <a 
href="https://github.com/apache/skywalking/discussions/12572";>Occational 
ClassCircularityError</a>
+     */
+    private static void circularityErrorWorkaround() {
+        // these classes have been involved in intermittent 
ClassCircularityErrors during startup
+        // they don't need context storage, so it's safe to load them before 
installing the agent
+        try {
+            Class.forName("java.util.concurrent.ThreadLocalRandom");
+        } catch (Throwable ignore) {
+        }
+    }
+
     /**
      * Main entrance. Use byte-buddy transform to enhance all classes, which 
define in plugins.
      */
@@ -114,22 +133,22 @@ public class SkyWalkingAgent {
         }
 
         Runtime.getRuntime()
-               .addShutdownHook(new Thread(ServiceManager.INSTANCE::shutdown, 
"skywalking service shutdown thread"));
+                .addShutdownHook(new Thread(ServiceManager.INSTANCE::shutdown, 
"skywalking service shutdown thread"));
     }
 
     static void installClassTransformer(Instrumentation instrumentation, 
PluginFinder pluginFinder) throws Exception {
         LOGGER.info("Skywalking agent begin to install transformer ...");
 
         AgentBuilder agentBuilder = newAgentBuilder().ignore(
-            nameStartsWith("net.bytebuddy.")
-                .or(nameStartsWith("org.slf4j."))
-                .or(nameStartsWith("org.groovy."))
-                .or(nameContains("javassist"))
-                .or(nameContains(".asm."))
-                .or(nameContains(".reflectasm."))
-                .or(nameStartsWith("sun.reflect"))
-                .or(allSkyWalkingAgentExcludeToolkit())
-                .or(ElementMatchers.isSynthetic()));
+                nameStartsWith("net.bytebuddy.")
+                        .or(nameStartsWith("org.slf4j."))
+                        .or(nameStartsWith("org.groovy."))
+                        .or(nameContains("javassist"))
+                        .or(nameContains(".asm."))
+                        .or(nameContains(".reflectasm."))
+                        .or(nameStartsWith("sun.reflect"))
+                        .or(allSkyWalkingAgentExcludeToolkit())
+                        .or(ElementMatchers.isSynthetic()));
 
         JDK9ModuleExporter.EdgeClasses edgeClasses = new 
JDK9ModuleExporter.EdgeClasses();
         try {
@@ -145,11 +164,11 @@ public class SkyWalkingAgent {
         }
 
         agentBuilder.type(pluginFinder.buildMatch())
-                    .transform(new Transformer(pluginFinder))
-                    .with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
-                    .with(new RedefinitionListener())
-                    .with(new Listener())
-                    .installOn(instrumentation);
+                .transform(new Transformer(pluginFinder))
+                .with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
+                .with(new RedefinitionListener())
+                .with(new Listener())
+                .installOn(instrumentation);
 
         PluginFinder.pluginInitCompleted();
 
@@ -191,7 +210,7 @@ public class SkyWalkingAgent {
                 EnhanceContext context = new EnhanceContext();
                 for (AbstractClassEnhancePluginDefine define : pluginDefines) {
                     DynamicType.Builder<?> possibleNewBuilder = define.define(
-                        typeDescription, newBuilder, classLoader, context);
+                            typeDescription, newBuilder, classLoader, context);
                     if (possibleNewBuilder != null) {
                         newBuilder = possibleNewBuilder;
                     }
diff --git a/dist-material/LICENSE b/dist-material/LICENSE
index a5c6f781cf..1d7a6f6ee3 100755
--- a/dist-material/LICENSE
+++ b/dist-material/LICENSE
@@ -215,7 +215,7 @@ Apache 2.0 licenses
 The following components are provided under the Apache License. See project 
link for details.
 The text of each license is the standard Apache 2.0 license.
 
-    raphw (byte-buddy) 1.14.9: http://bytebuddy.net/ , Apache 2.0
+    raphw (byte-buddy) 1.15.1: http://bytebuddy.net/ , Apache 2.0
     Google: grpc-java 1.53.0: https://github.com/grpc/grpc-java, Apache 2.0
     Google: gson 2.8.9: https://github.com/google/gson , Apache 2.0
     Google: proto-google-common-protos 2.0.1: 
https://github.com/googleapis/googleapis , Apache 2.0
diff --git a/pom.xml b/pom.xml
index adac36458d..0376e4be18 100755
--- a/pom.xml
+++ b/pom.xml
@@ -86,7 +86,7 @@
         <lombok.version>1.18.30</lombok.version>
 
         <!-- core lib dependency -->
-        <bytebuddy.version>1.14.9</bytebuddy.version>
+        <bytebuddy.version>1.15.1</bytebuddy.version>
         <grpc.version>1.53.0</grpc.version>
         <netty.version>4.1.100.Final</netty.version>
         <gson.version>2.8.9</gson.version>

Reply via email to