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

【bug反馈】RPC clint的版本设置无效 #1297

Closed
wojiukankan opened this issue May 24, 2020 · 0 comments
Closed

【bug反馈】RPC clint的版本设置无效 #1297

wojiukankan opened this issue May 24, 2020 · 0 comments
Assignees
Milestone

Comments

@wojiukankan
Copy link

    /**
     * @Reference(pool="user.pool",version="1.0")
     *
     * @var TestInterface
     */
    private $testService;

    /**
     * @Reference(pool="user.pool",version="2.0")
     * @var TestInterface
     */
    private $testServiceV2;

通过上述方式分别注入TestInterface的1.0版本和2.0版本。实际调用的时候,1.0会被2.0覆盖掉,
我看了一下源码发现:
swoft/rpc-client组件:
Swoft\Rpc\Client\Proxy.phpnewClassName()方法有一行:

return BaseProxy::newClassName($className, $visitor);

它调用了组件swoft/proxySwoft\Proxy\Proxy.phpnewClassName()方法
而有newClassName()方法中又有

if (isset(self::$caches[$className])) {
    return self::$caches[$className];
}

传入类名相同时,如果存在已有代理类则不生成直接返回原有代理类。

上述代码中的$className都是要生成代理类的类名,也就是TestInterface
所以,实际上生成1.0和2.0两个版本的TestInterface代理类时,由于两次调用BaseProxy::newClassName($className, $visitor);传递的类名是一样的,导致两个不同版本的代理类实际上只有第一次成功创建了代理类,第二次创建返回的是cache中历史数据。

考虑的修复方法是,调用创建代理类的方法时把版本带上,然后将代理类保存在cache的时候,健名也带上版本号。需要修改swoft/rpc-clientswoft/proxy两个组件

@inhere inhere added this to the v2.0.10 milestone May 24, 2020
inhere added a commit to swoft-cloud/swoft-proxy that referenced this issue Sep 13, 2020
inhere added a commit to swoft-cloud/swoft-rpc-client that referenced this issue Sep 13, 2020
inhere added a commit to swoft-cloud/swoft-aop that referenced this issue Sep 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants