Skip to content

[Bug] The follow-up with skywalking-java can not coexist with other agents. #9698 #9701

Closed
@SLAMDUNK7

Description

@SLAMDUNK7

Search before asking

  • I had searched in the issues and found no similar issues.

Apache SkyWalking Component

Java Agent (apache/skywalking-java)

What happened

Excuse me again. Thank you for wu-sheng's help, change the order of skywalking can resolve this problem, but thanks to our community partners for their thoughts.I find the primary cause of this problem,I hope this can help you.

I have found the reason for this problem. The problem described in #9698 will occur when the classes that skywalking is intended to enhance and they are used in agents added before skywalking.
The reason as follow :
Skywalking uses byte-buddy, when it structures byte-buddy's AgentBuilder, it select 'SinglePass (Default)' as it's 'DiscoveryStrategy'.

/**
 * A discovery strategy that considers all loaded types supplied by {@link Instrumentation#getAllLoadedClasses()}.
 */
enum SinglePass implements AgentBuilder.RedefinitionStrategy.DiscoveryStrategy {

    /**
     * The singleton instance.
     */
    INSTANCE;

    /**
     * {@inheritDoc}
     */
    public Iterable<Iterable<Class<?>>> resolve(Instrumentation instrumentation) {
        return Collections.<Iterable<Class<?>>>singleton(Arrays.<Class<?>>asList(instrumentation.getAllLoadedClasses()));
    }
}

DiscovertStrategy.SinglePass will discovery all loaded classes and then if skywaling need to enhance them in AgentBuilder.installOn, they will be retransformed.
image

In AgentBuilder.installOn process:

  1. As first step in the picture, the classes that have been not loaded will be transform,.
  2. As second step in the picture,the classes tha have been loaded will be discovered by 'DiscovertStrategy.SinglePass' and will be
    retransformed.

We quoted the 'instrumentation. RetransformClasses()' restrictions:

The retransformation must not add, remove or rename fields or methods, change the signatures of methods, or change inheritance.

It means that,when agent try to retransform classes, the above restrictions need to be observed.But i find that, when skywalking enhance a classes, it will change the class's inheritance.
image

If this class(can be system class) has been loaded by other agent before skywalking's premain,when skywalking enhance this class the Instrumentation.retransformClasses() will throw:

java.lang.UnsupportedOperationException: class redefinition failed: attempted to change superclass or interfaces

Because skywalking attemp to change a class's inheritace in retransform process.

What you expected to happen

I hope it can help skywalking. And i expect skywalking-java can coexist with other agents.

How to reproduce

Agent version:8.11.0
Plugin:apm-guava-eventbus-plugin
The command is like '-javaagent:xxxx-agent.jar -javaagent:skywalking-agent.jar'.

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    core featureCore and important feature. Sometimes, break backwards compatibility.discussionDiscussionsjavaJava agent related

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions