dubbo: No such extension org.apache.dubbo.rpc.cluster.LoadBalance by name random
- I have searched the issues of this repository and believe that this is not a duplicate.
- I have checked the FAQ of this repository and believe that this is not a duplicate.
Environment
- Dubbo version: 2.7.3
- Operating System version: Linux version 3.10.0-957.27.2.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) )
- Java version: openjdk 11.0.2
Steps to reproduce this issue
@Reference
private UserService userService;
@GetMapping("/v1/user/relation/trace/test2")
public CompletableFuture<String> dubbo2Test() {
return CompletableFuture.supplyAsync(() -> {
return userService.getUserInfo("sam");
}).thenApply(userInfo -> "s");
}
- dubbo config: it’s very simple:
dubbo.registry.address=xxx
dubbo.reference.check=false
- visit /v1/user/relation/trace/test2
Expected Result
“s”
Actual Result
2020-03-05 11:28:30.196 [ForkJoinPool.commonPool-worker-3] ERROR esa.restlight.core.bootstrap.DefaultDispatcherHandler - Error occurred when doing request(url=/v1/user/relation/trace/test2, method =GET)
java.util.concurrent.CompletionException: java.lang.IllegalStateException: No such extension org.apache.dubbo.rpc.cluster.LoadBalance by name random
at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:314)
at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:319)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1702)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1692)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:177)
Caused by: java.lang.IllegalStateException: No such extension org.apache.dubbo.rpc.cluster.LoadBalance by name random
at org.apache.dubbo.common.extension.ExtensionLoader.findException(ExtensionLoader.java:520)
at org.apache.dubbo.common.extension.ExtensionLoader.createExtension(ExtensionLoader.java:527)
at org.apache.dubbo.common.extension.ExtensionLoader.getExtension(ExtensionLoader.java:351)
at org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker.initLoadBalance(AbstractClusterInvoker.java:296)
at org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker.invoke(AbstractClusterInvoker.java:246)
at org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker.invoke(MockClusterInvoker.java:78)
at org.apache.dubbo.rpc.proxy.InvokerInvocationHandler.invoke(InvokerInvocationHandler.java:55)
at org.apache.dubbo.common.bytecode.proxy0.getUserInfo(proxy0.java)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor$ReferenceBeanInvocationHandler.invoke(ReferenceAnnotationBeanPostProcessor.java:260)
at com.sun.proxy.$Proxy72.getUserInfo(Unknown Source)
at com.heytap.ugc.user.relation.rest.controller.TestController.lambda$dubbo2Test$34(TestController.java:182)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1700)
... 6 common frames omitted
point: only when ForkJoinPool.commonPool thread call userService.getUserInfo can reproduce this issue
About this issue
- Original URL
- State: open
- Created 7 years ago
- Comments: 16 (2 by maintainers)
Commits related to this issue
- Fix dubbo's illegalStateException raised by completableFuture that uses different classloader same issue as https://github.com/apache/dubbo/issues/5829 — committed to CurtisNewbie/auth-module by CurtisNewbie 5 years ago
For those still using Dubbo 2.7.x and encountering similar issues, there is a workaround involving Pre-loading of necessary SPIs by a thread with the ‘correct’ class loader:
If you’re using SpringBoot integrated with Dubbo, you can add the following code right after the service is ready(e.g. attach it with the SmartLiftcycle interface). This will ensure that the code is executed by a Spring-managed thread, which uses the same class loader as Dubbo:
Pre-load solution
What cause this?
Under Dubbo 2.7.17 version, the source code of org.apache.dubbo.common.extension.ExtensionLoader#getExtensionClasses is taking the Dubbo-Check-Lock(DCL) strategy, and Dubbo only loads needed SPI when needed (similar to lazy initialization):
As the replies above mentioned, inner logic for org.apache.dubbo.common.extension.ExtensionLoader#loadExtensionClasses
would use calling thread’s class loader in org.apache.dubbo.common.utils.ClassUtils#getClassLoader(java.lang.Class<?>)
So the first Thread call the getExtensionClasses is crucial, or else incorrect classloader return would affect all later requests (loadExtensionClasses would never return null).
Why the workaround works?
Thus, the above workaround is using the Spring-handled thread (classloader would be LaunchedURLClassLoader in the executable jar file) to initialise that cachedClasses because:
Did Dubbo 3.x solve this?
They do make some changes in the ClassUtils (3.2 ver), by the class which start with “org.apache.dubbo”, they just use the target class’s classloader rather than get if from current Thread.
Hope this comment helps anyone struggling with this 😃
Tried to customize my own ForkJoinPoolThreadFactory, and set by -Djava.util.concurrent.ForkJoinPool.common.threadFactory=MyFactory But it’s not working in a spring boot application bacause ForkJoinPool uses AppClassLoader(returned by ClassLoader.getSystemClassLoader()) to load the MyFactory.class and ClassNotFoundException will be thrown. The rigth classloader would be spring boot’s own classloader called LaunchedURLClassLoader
Still wondering!