dubbo开启token服务后,使用集群容错策略为FailoverClusterInvoker,当出现服务调用失败进行转移,重试其它服务器时,会出现token invalid错误,provider会拒绝服务调用。

原因:

消费端:

1、com.alibaba.dubbo.rpc.cluster.support.FailoverClusterInvoker#doInvoke:

   for (int i = 0; i < len; i++) {//重试时,进行重新选择,避免重试时invoker列表已发生变化.//注意:如果列表发生了变化,那么invoked判断会失效,因为invoker示例已经改变if (i > 0) {checkWheatherDestoried();copyinvokers = list(invocation);//重新检查一下checkInvokers(copyinvokers, invocation);}Invoker<T> invoker = select(loadbalance, invocation, copyinvokers, invoked);invoked.add(invoker);RpcContext.getContext().setInvokers((List)invoked);try {if (le != null && logger.isWarnEnabled()) {logger.warn("Although retry the method " + invocation.getMethodName()+ " in the service " + getInterface().getName()+ " was successful by the provider " + invoker.getUrl().getAddress()+ ", but there have been failed providers " + providers + " (" + providers.size() + "/" + copyinvokers.size()+ ") from the registry " + directory.getUrl().getAddress()+ " on the consumer " + NetUtils.getLocalHost()+ " using the dubbo version " + Version.getVersion() + ". Last error is: "+ le.getMessage(), le);}return result;} catch (RpcException e) {if (e.isBiz()) { // biz exception.throw e;}le = e;} catch (Throwable e) {le = new RpcException(e.getMessage(), e);} finally {providers.add(invoker.getUrl().getAddress());}

2、com.alibaba.dubbo.rpc.protocol.AbstractInvoker#invoke

  RpcInvocation invocation = (RpcInvocation) inv;invocation.setInvoker(this);if (attachment != null && attachment.size() > 0) {invocation.addAttachmentsIfAbsent(attachment);  //添加相关参数到附件attachments,如token}Map<String, String> context = RpcContext.getContext().getAttachments();if (context != null) {invocation.addAttachmentsIfAbsent(context);}

3、addAttachmentsIfAbsent实现:

    public void setAttachmentIfAbsent(String key, String value) {if (attachments == null) {attachments = new HashMap<String, String>();}if (! attachments.containsKey(key)) {  //key不存在时才进行赋值,因此不能进行覆盖操作attachments.put(key, value);}}

服务提供方:

public class TokenFilter implements Filter {public Result invoke(Invoker<?> invoker, Invocation inv)throws RpcException {String token = invoker.getUrl().getParameter(Constants.TOKEN_KEY);if (ConfigUtils.isNotEmpty(token)) {Class<?> serviceType = invoker.getInterface();Map<String, String> attachments = inv.getAttachments();//解析attachments String remoteToken = attachments == null ? null : attachments.get(Constants.TOKEN_KEY);if (! token.equals(remoteToken)) {throw new RpcException("Invalid token! Forbid invoke remote service " + serviceType + " method " + inv.getMethodName() + "() from consumer " + RpcContext.getContext().getRemoteHost() + " to provider "  + RpcContext.getContext().getLocalHost());}}return invoker.invoke(inv);}}

通过上面的代码分析可知,当消费者调用服务方服务出现超时进行失败重连时,要重连的Invoker的token没有覆盖上一次的invoker的token,而服务端比较token时比较的是attachment, 进而出现token invalid错误。相当于失败重连无效.

错误现象:

1、请求超时,此时token是一致的
telnet=invoke,status,replacetoken&timeout=1000&timestamp=1418813410249&token=020f16e2-e060-4c85-a31a-017aa0ee268c&version=1.0, cause: Waiting server-side response timeout. start time: 2014-12-17 21:42:26.735, end time: 2014-12-17 21:42:27.736, client elapsed: 0 ms, server elapsed: 1001 ms, timeout: 1000 ms, request: Request [id=27484, version=2.0.0, twoway=true, event=false, broken=false, data=RpcInvocation […], attachments={token=020f16e2-e060-4c85-a31a-017aa0ee268c,

。。。。。。。
2、失败重连,此时附件token与url的不一致
…&pid=29465&revision=1.0.1&side=consumer&status=spring,load&telnet=invoke,status,replacetoken&timeout=1000&timestamp=1418813410249
&token=0f3103ad-ac7b-4906-897c-b51e69ab3b96&version=1.0 -> RpcInvocation […],
attachments={token=020f16e2-e060-4c85-a31a-017aa0ee268c,
。。。。。。。
3、出现token invalid
com.alibaba.dubbo.rpc.RpcException: Invalid token! Forbid invoke remote service interface

可以将token设置为false解决

Dubbo调用时报错Invalid token Forbid invoke remote service interface相关推荐

  1. Dubbo3注册为应用级时报错“No provider available for the service XXX”

    文章目录 Dubbo3注册模式介绍 踩坑记录 Dubbo3注册为应用级时,Nacos注册中心看到注册服务服务和订阅列表均正常,但是实际调用时报错"No provider available ...

  2. python中使用tomorrow多线程时报错invalid syntax

    python中使用tomorrow多线程时报错invalid syntax如何解决?具体报错信息如下: 解决方案: 需要点击打开tomorrow.py文件,把42行的async改个名称,因为async ...

  3. sklearn安装成功,调用时报错NO Module “sklearn“

    sklearn安装成功,调用时报错NO Module "sklearn" 1.问题描述 2.解决办法 1.问题描述 在调试程序时,报错没有sklearn,然后用pip安装了skle ...

  4. spark报错:invalid token

    启动spark报错,启动container失败,去看yarn的日志,显示invalid token, 经过排查是hadoop子节点的配置和主节点的配置不一致导致的,同步之后,问题解决. 转载于:htt ...

  5. 解决pod时报错“Authentication token is invalid or unverified. Either verify it with the email that…”问题

    执行pod trunk push时报了下面这个错误: [!] Authentication token is invalid or unverified. Either verify it with ...

  6. eclipse 项目导入时报错invalid project description

    最近从网络上下载一个开源框架Demo示例,使用Eclipse导入该项目,报错:invalid project description. 经百度后,得知项目文件夹下,.project文件上项目名称必须保 ...

  7. 接口缺方法调用时报错_TypeScript真香系列——接口篇

       戳蓝字「前端技术优选」关注我们哦! 接口带来了什么好处 好处One -- 过去我们写 JavaScript JavaScript 中定义一个函数,用来获取一个用户的姓名和年龄的字符串: cons ...

  8. webpack设置打包入口后运行时报错Invalid configuration object. Webpack has been initialized using a configuration

    报错的原因是./dist不是一个绝对路径 需要把上面的path的值设置为绝对路径

  9. create-react-app部署到GitHub Pages时报错:Failed to get remote。origin.url

    最近使用create-react-app脚手架开发了一个私人博客:点击跳转,在部署到GitHub Pages的时候报了一个错误,具体如下: 在create-react-app的GitHub库的issu ...

最新文章

  1. Node.js复制/删除服务器端文件到指定目录文件夹下,并且预判是否存在该目录,如果没有,则递归创建该文件夹目录
  2. [译] ASP.NET 生命周期 – ASP.NET 上下文对象(六)
  3. smarty模板引擎原理解析
  4. Hello Las Vegas | 博云在微软Inspire大会的4个思考
  5. 【Android 安装包优化】WebP 应用 ( Android 中使用 libwebp.so 库编码 WebP 图片 )
  6. oracle 获取系统年 月,Oracle 获取当前年、月、日
  7. byte转化为Bitmap,防止内存溢出
  8. 三星sec.android.soagent,3.0降级2.5教程
  9. HDOJ 1021-1025
  10. mysql sharding 方案_mysql sharding 方案 分库分表(sharding)系列(4)
  11. 三维点云学习(1)下-点云体素降采样
  12. Unity AssetsBundle
  13. python day 1 homework 1
  14. Cloudera迁移scm数据库
  15. Excel图标美化技巧
  16. IPhone手机无法连接蓝牙
  17. VMware ESXi添加NVMe硬盘扩容
  18. TCP/IP协议簇中的子网掩码有什么作用
  19. BUUCTF 打卡2
  20. 大数据分析培训课程机器学习

热门文章

  1. html留言板 php,linux下使用Apache+php实现留言板功能的网站
  2. mysql myisam 支持事务吗_第三章(附)mysql表类型MyISAM和InnoDB区别(决定了是否支持事务)...
  3. Nginx的配置实例(反向代理准备工作)
  4. 冯提莫在B站的受欢迎度
  5. 基于matlab的pcb焊盘,EDA复习题
  6. Java基础之this关键字和super关键字区别
  7. Java的面试汇总,有这些还担心不通过?
  8. w7电脑蓝屏怎么解决_怎么解决0x0000007b电脑蓝屏 解决0x0000007b电脑蓝屏方法【详细步骤】...
  9. java如何画百分比圆环_canvas绘制百分比圆环进度条
  10. 什么笔记本电脑好用_苹果笔记本好用吗?苹果笔记本怎么样?