Open githubcheng2978 opened 3 months ago
What is the exception?
java.lang.IllegalAccessError: tried to access class org.apache.http.impl.client.InternalHttpClient$$sw$auxiliary$8shium3 from class org.apache.http.impl.client.InternalHttpClient
Are you using the module system? It's hard to tell from your code why this is. Are the two classes on different class loaders?
I assume that your intercepted class is not visible to your intercepted code. The exception suggests that you are loading code on different class loaders. You should avoid auxiliary classes on agents for this reason. Maybe have a look at Advice
to avoid it,
I use the Skywalking agent, and the key code is as follows:
newClassBuilder = newClassBuilder.method(junction) .intercept(MethodDelegation.withDefaultConfiguration() .to(new InstMethodsInter(interceptor, classLoader), delegateNamingResolver.resolve(instanceMethodsInterceptPoint)));
What is the class of generated auxiliary: `class InternalHttpClient$$sw$auxiliary$urqm873 implements Runnable, Callable { private InternalHttpClient argument0; private HttpHost argument1; private HttpRequest argument2; private HttpContext argument3;
public Object call() throws Exception {
return this.argument0.$sw$original$doExecute$7gb7dq1$accessor$$sw$l56slt2(this.argument1, this.argument2, this.argument3);
}
public void run() {
this.argument0.$sw$original$doExecute$7gb7dq1$accessor$$sw$l56slt2(this.argument1, this.argument2, this.argument3);
}
InternalHttpClient$$sw$auxiliary$urqm873(InternalHttpClient var1, HttpHost var2, HttpRequest var3, HttpContext var4) {
this.argument0 = var1;
this.argument1 = var2;
this.argument2 = var3;
this.argument3 = var4;
}
}`
it's a proxy to invoke the super method of the intercepted code. It needs to be injected into the right class loader. Did you configure a proper injection strategy?
the injection strategy is:
ClassInjector.UsingUnsafe.Factory factory = ClassInjector.UsingUnsafe.Factory.resolve(instrumentation);
factory.make(null, null).injectRaw(classesTypeMap);
agentBuilder = agentBuilder.with(new AgentBuilder.InjectionStrategy.UsingUnsafe.OfFactory(factory));
Not sure why you encounter this. Might it be that injected classes end up on two class loaders?
My project uses Skywalking and Apache HTTP client. At the same time, a third-party SDK was used in the project, which also introduced the Apache HTTP client through a jar package. The SDK customized a classloader to load its own jar. If I prioritize initializing the SDK, the project is normal, but if I prior itize initializing the HTTP client in the project, an exception will be thrown I wrote a simple demo: Demo.zip
download site: https://dlcdn.apache.org/skywalking/java-agent/9.2.0/apache-skywalking-java-agent-9.2.0.tgz and add jvm options with agent. -javaagent:/home/blue/workspace/skywalking-agent/skywalking-agent.jar
Plugins that require bootstrap to be enabled. change config/agent.config plugin.mount=plugins,bootstrap-plugins
I would assume that this is related to the Skywalking agent somehow, I would suggest you reach out to the maintainers there.
I also tried to get help in Skywalking, and the answer I got was the problem with the class loader. I don't know exactly where the problem occurred, so I came here to seek help
Not sure if I can help. This seems to be related to how the instrumentation is implemented. In general, if you create a class on two class loaders on the same hirarchy, this will often lead to hanging.
when i use two agentBuilder(use InjectionStrategy.UsingUnsafe to enhance jdk classes,use InjectionStrategy.UsingReflection.INSTANCE to enhance other classes), the error disappeared
Then you might have it some module boundary before. Handles are not as powerful as injection, but use standard API.
ClassInjector.UsingUnsafe.Factory factory = ClassInjector.UsingUnsafe.Factory.resolve(instrumentation); factory.make(null, null).injectRaw(classesTypeMap); agentBuilder = agentBuilder.with(new AgentBuilder.InjectionStrategy.UsingUnsafe.OfFactory(factory));
public class IClassLoader extends URLClassLoader { private static final String version = "1.0.0.5"; private static IClassLoader instance; private OpenClassLoader parent; private static final boolean isForceUpdate = false; private static final String standardClasspathConfigFile = "/sar/sar.properties"; private static final String standardClasspathDir = "/sar/jars/"; private static String workDir = System.getProperty("user.home");
} ` the code 'org.apache.http.impl.client.CloseableHttpClient' in "/sar/jars/" + jarName。 springboot project has also 'org.apache.http.impl.client.CloseableHttpClient'
when i delete code InjectionStrategy.UsingUnsafe.OfFactor, my applicaiotn works well. but, throw an exception。
help me~~ this is production incident