liaosiqian opened a new issue #9343:
URL: https://github.com/apache/dubbo/issues/9343


   <!-- If you need to report a security issue please visit 
https://github.com/apache/dubbo/security/policy -->
   
   - [ ] I have searched the [issues](https://github.com/apache/dubbo/issues) 
of this repository and believe that this is not a duplicate.
   
   ### Environment
   
   * Dubbo version: 3.0.2
   * Operating System version: linux
   * Java version: 1.8
   
   ### Steps to reproduce this issue
   
   1. 两个提供方,dubbo.tag 分别为   noTag  和  custom
   2. 消费方通过 “ 
RpcContext.getClientAttachment().setAttachment("dubbo.tag","custom");” 
动态设置想要调用的提供方
   3. 执行调用提供方
   
   Pls. provide [GitHub address] to reproduce this issue.
   
   ### Expected Behavior
   期望根据 消费方指定的 dubbo.tag 进行调用
   
   ### Actual Behavior
   调用到了   dubbo.tag =noTag的 提供方
   
   排查结论:
   1、在 org.apache.dubbo.rpc.cluster.router.tag.TagDynamicStateRouter#pool 
初始化时,由于没有设置
   org.apache.dubbo.rpc.cluster.router.tag.TagDynamicStateRouter#tagRouterRule, 
导致所有的服务提供方均被打上“noTag”标签
   
![动态路由-pool](https://user-images.githubusercontent.com/15165772/144376799-a2fe9802-39bb-49a5-a351-fc6db2cf103f.png)
   
   2、在进行路由选择时,org.apache.dubbo.rpc.cluster.RouterChain#route,
   会通过 TagDynamicStateRouter 和 TagStaticStateRouter  进行最终调用者的筛选时
   
![动态路由-pool](https://user-images.githubusercontent.com/15165772/144379016-bb3e84e2-9524-49af-8ce3-0d179b56f26e.png)
   
   
   3、由于消费方主动设置了 dubbo.tag ,
   因此 
动态路由在筛选时(org.apache.dubbo.rpc.cluster.router.tag.TagDynamicStateRouter#route)会尝试获取
  tag=custom的 服务提供方;
   
![动态路由-route](https://user-images.githubusercontent.com/15165772/144379035-3774b24e-a249-416b-97a9-444a556695cb.png)
   
   ```
       @Override
       public <T> BitList<Invoker<T>> route(BitList<Invoker<T>> invokers, 
RouterCache<T> cache, URL url,
           Invocation invocation) throws RpcException {
   
           
           final TagRouterRule tagRouterRuleCopy = 
(TagRouterRule)cache.getAddrMetadata();
          // 此处由于消费方设置 dubbo.tag ,因此优先取  attacthment中的 dubbo.tag
           String tag = StringUtils.isEmpty(invocation.getAttachment(TAG_KEY)) 
? url.getParameter(TAG_KEY) :
               invocation.getAttachment(TAG_KEY);
   
           ConcurrentMap<String, BitList<Invoker<T>>> addrPool = 
cache.getAddrPool();
   
           if (StringUtils.isEmpty(tag)) {
               return invokers.intersect(addrPool.get(NO_TAG), 
invokers.getUnmodifiableList());
           } else {
               // 尝试从动态缓存池中拉取 tag=custom的 服务列表,很显然拉不到(因为没有配置动态路由规则)
               BitList<Invoker<T>> result = addrPool.get(tag);
              
               if (CollectionUtils.isNotEmpty(result) || (tagRouterRuleCopy != 
null && tagRouterRuleCopy.isForce())
                   || isForceUseTag(invocation)) {
                   return invokers.intersect(result, 
invokers.getUnmodifiableList());
               } else {
                   // 触发该分支,进而导致  attachment被重置成 noTag ,造成 dubbo.tag失效的问题
                   invocation.setAttachment(TAG_KEY, NO_TAG);
                   return invokers;
               }
           }
       }
   ```
   结果由于初始化时没有设置该标签的服务提供方,导致了获取不到对应的服务提供方,并且还重置了 dubbo.tag
   
   4、由于此时的dubbo.tag被重置成了 noTag 
,最终在静态路由筛选过程中(org.apache.dubbo.rpc.cluster.router.tag.TagStaticStateRouter#route),
    中,一样获取不到,进而导致了 通过设置  
RpcContext.getClientAttachment().setAttachment("dubbo.tag","custom") 不能正常生效的问题
   
   
   想确认的点:
   1、TagDynamicStateRouter 和 TagStaticStateRouter  是否在未来的版本中会被移除;
   目前发现在 3.0.x-dev 和 master版本均为找到该内容;
   
   2、在 org.apache.dubbo.rpc.cluster.router.tag.TagDynamicStateRouter#route 中  
重置 dubbo.tag 的意义?
   我们将之移除是否有影响。
   
   3、dubbo.tag 是否应该被重置


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to