Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trpc启动时RpcClientFactory未注册导致client调用时报错com.tencent.trpc.core.exception.TRpcExtensionException: Cannot get extension of type <com.tencent.trpc.core.rpc.spi.RpcClientFactory> with name <trpc> #46

Closed
sdwdgx4018 opened this issue Jun 14, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@sdwdgx4018
Copy link

springboot接入trpc,使用北极星路由,在调用client时报错;
Caused by: com.tencent.trpc.core.exception.TRpcExtensionException: Cannot get extension of type <com.tencent.trpc.core.rpc.spi.RpcClientFactory> with name
at com.tencent.trpc.core.extension.ExtensionLoader.lambda$getExtension$5(ExtensionLoader.java:241) ~[trpc-core-1.1.1.jar!/:na]
at java.base/java.util.Optional.orElseThrow(Optional.java:403) ~[na:na]
at com.tencent.trpc.core.extension.ExtensionLoader.getExtension(ExtensionLoader.java:240) ~[trpc-core-1.1.1.jar!/:na]
at com.tencent.trpc.core.common.config.ProtocolConfig.createClient(ProtocolConfig.java:97) ~[trpc-core-1.1.1.jar!/:na]
at com.tencent.trpc.core.cluster.RpcClusterClientManager.createRpcClientProxy(RpcClusterClientManager.java:159) ~[trpc-core-1.1.1.jar!/:na]
at com.tencent.trpc.core.cluster.RpcClusterClientManager.lambda$getOrCreateClient$11(RpcClusterClientManager.java:152) ~[trpc-core-1.1.1.jar!/:na]
at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708) ~[na:na]
at com.tencent.trpc.core.cluster.RpcClusterClientManager.getOrCreateClient(RpcClusterClientManager.java:151) ~[trpc-core-1.1.1.jar!/:na]
at com.tencent.trpc.core.cluster.def.DefClusterInvoker.createInvoker(DefClusterInvoker.java:96) ~[trpc-core-1.1.1.jar!/:na]

打开debug日志发现服务启动时warmupClient的日志到Warm up client create&open 后就不执行了,也没有异常Warm up client create&open exception

@sdwdgx4018
Copy link
Author

本地启动服务是正常的,打包部署到容器里有问题;刚远程debug试了一下ExtensionLoader.cachedExtensionClasses是空的,重新调用loadExtensionClasses()后是有值的

@sdwdgx4018
Copy link
Author

多核情况下子线程的classloader和主线程的classloader同时加载资源,出现资源竞争,主子线程公用同一个资源的引用,主线程消费后,子线程就不消费了。导致子线程没有加载成功;clazz.getClassLoader()可以保证多线程并发时返回的classloader是相同的;
public class ClassLoaderUtils {

/**
 * Get the current ClassLoader.
 */
public static ClassLoader getClassLoader(Class<?> clazz) {
    ClassLoader loader = ConfigManager.getInstance().getCachedClassLoader();
    if (loader != null) {
        return loader;
    }
    loader = Thread.currentThread().getContextClassLoader();
    if (loader != null) {
        return loader;
    }
    if (clazz != null) {
        loader = clazz.getClassLoader();
        if (loader != null) {
            return loader;
        }
    }
    return ClassLoader.getSystemClassLoader();
}

}

@sdwdgx4018
Copy link
Author

建议去掉使用线程级的classloader,使用类的classloader;可解决资源加载异常的问题

@wardseptember
Copy link
Collaborator

wardseptember commented Jun 18, 2024

你的springboot是怎么接入trpc,方便发一下配置或者代码吗,我们看下具体的问题。怎么样可以方便的复现

建议去掉使用线程级的classloader,使用类的classloader;可解决资源加载异常的问题

@sdwdgx4018
Copy link
Author

sdwdgx4018 commented Jun 20, 2024

你的springboot是怎么接入trpc,方便发一下配置或者代码吗,我们看下具体的问题。怎么样可以方便的复现

建议去掉使用线程级的classloader,使用类的classloader;可解决资源加载异常的问题

这是客户端的配置,也同时对外提供服务

trpc:
  #全局配置
  global:
    namespace: dev  #环境类型,分正式环境和非正式环境两种类型
    env_name: dev   #环境名称,非正式环境下多环境的名称
  server:
    app: scp
    server: scp-rule-service
    service:
      - name: scp.rule.service
        impls: # Service implement classes
          - com.xxx.scp.rule.app.trpc.TemplateTRpcServiceAPIImpl
        port: 8082       # Listen port
        protocol: trpc
        transporter: netty
        serialization: pb
  client: # Client configs
    request_timeout: 300000
    service:
      - name: scp.invoker.service  # Service name
        naming_url: polaris://scp.invoker.service
        port: 8083
        interface: com.xxx.scp.invoker.api.InvokerServiceAPI # Service interface
  plugins:
    registry:
      polaris: #名字注册服务的远程对象
        heartbeat_interval: 3000 #名字注册服务心跳上报间隔
        mode: 0                                      #选填,运行模式0-noagent 1-withagent
        protocol: grpc                               #选填,服务发现的rpc协议,暂时只支持grpc
        register_self: true
        service:
          - name: scp.rule.service
            namespace: dev #环境类型,分正式production和非正式development两种类型
        global:
          system:
            discoverCluster:
              sameAsBuiltin: true
            healthCheckCluster:
              sameAsBuiltin: true
          serverConnector:
            # target server address
            addresses:
              - polaristest.xxx.com:8091
          statReporter:
            enable: true
            plugin:
              prometheus:
                port: 28082
    selector:
      polaris:
        enable_trans_meta: true  # 使用规则路由时必须配置
        mode: 0
        # 以下的配置与polaris java sdk配置一致。
        global:
          system:
            discoverCluster:
              sameAsBuiltin: true
            healthCheckCluster:
              sameAsBuiltin: true
          serverConnector:
            # target server address
            addresses:
              - polaristest.xxx.com:8091
          statReporter:
            enable: true
            plugin:
              prometheus:
                port: 28081

@wardseptember
Copy link
Collaborator

@sdwdgx4018 配置看起来没啥,可以加一下我企微,我们具体看下,
wecom-temp-50635-3bfcd2420c89d82d1628ab7833fd315f

@wardseptember wardseptember added the bug Something isn't working label Aug 14, 2024
@wardseptember
Copy link
Collaborator

fix in #52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants