skywalking icon indicating copy to clipboard operation
skywalking copied to clipboard

Conflict with some mechanism in Dubbo 2.6.2

Open 3zamn opened this issue 8 years ago • 34 comments

Please answer these questions before submitting your issue.

  • Why do you submit this issue?
  • [x] Question or discussion
  • [x] Bug
  • [ ] Requirement
  • [x] Feature or performance improvement

Question

  • What do you want to know? extension.SpringExtensionFactory - [DUBBO] No spring extension(bean) named:skyWalkingDynamicField, try to find an extension(bean) of type java.lang.Object, dubbo version: oss, current host: 192.168.0.3 ERROR extension.ExtensionLoader - [DUBBO] fail to inject via method setSkyWalkingDynamicField of interface com.alibaba.dubbo.rpc.Filter:

Bug

  • Which version of SkyWalking, OS and JRE? SkyWalking5.6.0、dubbo2.6.2、jre1.8

  • Which company or project?

  • What happen? If possible, provide a way for reproducing the error. e.g. demo application, component version. dubbo2.6.0- is ok、but dubbo2.6.2+ didn't support


Requirement or improvement

Please support dubbo2.6.2+

3zamn avatar Oct 16 '18 02:10 3zamn

@ascrutae please take a look at this.

wu-sheng avatar Oct 16 '18 02:10 wu-sheng

@wu-sheng Hey, I also met this problem and I found the reason. Because Skywalking will add setSkyWalkingDynamicField(Object) to class MonitorFilter and this conflicts with dubbo's spi extention mechanism.

/*
 * com.alibaba.dubbo.common.extension.ExtensionLoader
 * Here dubbo's spi extention mechanism will traverse all the public set method
 */
private T injectExtension(T instance) {
    try {
        if (objectFactory != null) {
            for (Method method : instance.getClass().getMethods()) {
                if (method.getName().startsWith("set")
                        && method.getParameterTypes().length == 1
                        && Modifier.isPublic(method.getModifiers())) {
                    Class<?> pt = method.getParameterTypes()[0];
                    try {
                        String property = method.getName().length() > 3 ? method.getName().substring(3, 4).toLowerCase() + method.getName().substring(4) : "";
                        Object object = objectFactory.getExtension(pt, property);
                        if (object != null) {
                            method.invoke(instance, object);
                        }
                    } catch (Exception e) {
                        logger.error("fail to inject via method " + method.getName()
                                + " of interface " + type.getName() + ": " + e.getMessage(), e);
                    }
                }
            }
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    return instance;
}

Before dubbo 2.6.3, the extentionFactory just get bean by name, so there is no errro.

/*
 * com.alibaba.dubbo.config.spring.extension.SpringExtensionFactory
 */
@Override
@SuppressWarnings("unchecked")
public <T> T getExtension(Class<T> type, String name) {
    for (ApplicationContext context : contexts) {
        if (context.containsBean(name)) {
            Object bean = context.getBean(name);
            if (type.isInstance(bean)) {
                return (T) bean;
            }
        }
    }
    return null;
}

After, dubbo monify the code, it also get bean by type and this throw the exception.

@Override
@SuppressWarnings("unchecked")
public <T> T getExtension(Class<T> type, String name) {
    for (ApplicationContext context : contexts) {
        if (context.containsBean(name)) {
            Object bean = context.getBean(name);
            if (type.isInstance(bean)) {
                return (T) bean;
            }
        }
    }

    logger.warn("No spring extension(bean) named:" + name + ", try to find an extension(bean) of type " + type.getName());

    for (ApplicationContext context : contexts) {
        try {
            return context.getBean(type);
        } catch (NoUniqueBeanDefinitionException multiBeanExe) {
            //here will throw exception because setSkyWalkingDynamicField() type is Object and spring will find many beans
            throw multiBeanExe;
        } catch (NoSuchBeanDefinitionException noBeanExe) {
            if (logger.isDebugEnabled()) {
                logger.debug("Error when get spring extension(bean) for type:" + type.getName(), noBeanExe);
            }
        }
    }

    logger.warn("No spring extension(bean) named:" + name + ", type:" + type.getName() + " found, stop get bean.");

    return null;
}

Emmm....Maybe you can communicate with dubbo....

KerwinAusten avatar Oct 23 '18 02:10 KerwinAusten

@IcebergXTY Thanks for the feedback. I already dropped an request in Dubbo mail list, https://lists.apache.org/thread.html/ed79a0284fddfedc53c96e5666a059617693cd4d7628c32de2935ea4@%3Cdev.dubbo.apache.org%3E . Let's wait and see what are they going to response, and we could work from here.

wu-sheng avatar Oct 23 '18 03:10 wu-sheng

@chickenlj I've checked the git commit log, this change is from you. Could u pls. take some time to look at it?

diecui1202 avatar Oct 23 '18 03:10 diecui1202

Sure, I am here on it.

I guess the newly added method setSkyWalkingDynamicField(Object) from SkyWalking is not expected to be automatically injected by Dubbo framework. To make Dubbo more adaptable, I think we should do the following:

  1. A method level annotation to enable auto-injection or not.
  2. Special handling for generic Object parameter type.

chickenlj avatar Oct 23 '18 03:10 chickenlj

@IcebergXTY @wu-sheng Do you think this will solve your problem?

chickenlj avatar Oct 23 '18 03:10 chickenlj

A method level annotation to enable auto-injection or not.

@chickenlj I hope the default is not :) SkyWalking will add this method to all enhanced classes, we can't add an annotation belongs to Dubbo only, may trigger ClassNotFound in other scenarios.

Or, when could not find the inject way, just ignore. The auto set should not be active always from my perspective.

wu-sheng avatar Oct 23 '18 03:10 wu-sheng

A method level annotation to enable auto-injection or not.

@chickenlj I hope the default is not :) SkyWalking will add this method to all enhanced classes, we can't add an annotation belongs to Dubbo only, may trigger ClassNotFound in other scenarios.

Set the default value to not would bring lots of changes to Dubbo, many methods would need to add an annotation and enable injection. Can't SkyWalking just add an annotation when instrumenting Dubbo? Anyway, I think Dubbo need an annotation to flexibly control the injection action.

Or, when could not find the inject way, just ignore. The auto set should not be active always from my perspective.

Sounds reasonable, I will consider the possibility of ignoring it when fails.

chickenlj avatar Oct 23 '18 05:10 chickenlj

@chickenlj What is The parameter instance about injectExtension method, an MonitorFilter object?

ascrutae avatar Oct 23 '18 06:10 ascrutae

Set the default value to not would bring lots of changes to Dubbo, many methods would need to add an annotation and enable injection. Can't SkyWalking just add an annotation when instrumenting Dubbo? Anyway, I think Dubbo need an annotation to flexibly control the injection action.

In theory, we can. But we haven't that kind of core API to do so. So, I hope Dubbo can ignore that by the default mechanism. @chickenlj @diecui1202 Hope this could be fixed soon, and I will keep this open to track the status. If you have any solution, please leave the message here.

wu-sheng avatar Oct 23 '18 06:10 wu-sheng

I have created a patch to fix this problem, briefly changes:

  • Add optional Inject annotation for developers to decide open auto-injection or not.
  • Printing log instead of throwing Exception in SpringExtensionFactory when multi-extension or no extension found.

chickenlj avatar Oct 24 '18 04:10 chickenlj

Both of these are great. Especially just log rather than throw exception. :) Thank so much for helping. @chickenlj .

FYI @3zamn @IcebergXTY @ascrutae I think we just need to wait for new version of Dubbo. @chickenlj please info us after release done, then we can close this issue officially.

wu-sheng avatar Oct 24 '18 06:10 wu-sheng

@wu-sheng That's great!Thank you for your work! 😊

KerwinAusten avatar Oct 24 '18 14:10 KerwinAusten

@IcebergXTY The credits belong to Dubbo team. @chickenlj

wu-sheng avatar Oct 24 '18 14:10 wu-sheng

I think it will be released along with the upcoming Dubbo v2.6.5.

chickenlj avatar Oct 29 '18 07:10 chickenlj

I think it will be released along with the upcoming Dubbo v2.6.5.

@chickenlj Great to know. @IcebergXTY When you have time, please help to test SkyWalking on their incoming 2.6.5, then provide the feedback here.

wu-sheng avatar Oct 29 '18 13:10 wu-sheng

@wu-sheng @chickenlj I have updated to dubbo-2.6.5. It works well now. Excellent!

KerwinAusten avatar Nov 15 '18 05:11 KerwinAusten

@IcebergXTY @chickenlj 2.6.5 is already released or not?

wu-sheng avatar Nov 15 '18 06:11 wu-sheng

@ascrutae we need to add new dubbo version to our test cases. And we could remove some older ones.

wu-sheng avatar Nov 15 '18 06:11 wu-sheng

@wu-sheng I‘m not sure whether dubbo has released officially but the maven repository has already contained the dubbo-2.6.5

KerwinAusten avatar Nov 16 '18 01:11 KerwinAusten