You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2019/07/25 02:37:43 UTC

[GitHub] [dubbo-js] wushanchao edited a comment on issue #80: Node进程会偶尔与zk集群断开连接,导致socket无可用agent

wushanchao edited a comment on issue #80: Node进程会偶尔与zk集群断开连接,导致socket无可用agent
URL: https://github.com/apache/dubbo-js/issues/80#issuecomment-514863518
 
 
   > 发现一个 "似乎是" 的复现步骤。
   > 
   > 首先在本地启动一个可以运行的实例:
   > 
   > ```shell
   > # start docker
   > $ docker-compose up 
   > # start providers
   > $ java -jar target/dubbo-demo-provider-2.6.3-jar-with-dependencies.jar
   > # start example/hello-koa
   > $ npm run debug:start
   > ```
   > 
   > 详细的启动步骤参考 [for-contributors](https://github.com/apache/dubbo-js#for-contributors)
   > 
   > 在复现问题前,确保实例已经运行起来:
   > 
   > ```shell
   > curl http://localhost:3000/hello
   > ```
   > 
   > 如果看到 `Hello World` 的话,则可以开始复现问题
   > 
   > 第一步,手动删除 `/dubbo` 节点
   > 
   > ```shell
   > ```bash
   > # replace below port according your env
   > zkcli -server localhost:2182
   > # check what's in our ZK
   > ls /
   > # delete node `/dubbo`
   > rmr /dubbo/com.alibaba.dubbo.demo.BasicTypeProvider/consumers
   > rmr /dubbo/com.alibaba.dubbo.demo.ErrorProvider
   > rmr /dubbo
   > # check `/dubbo` has been deleted if it isn't in the output of below command
   > ls /
   > ```
   > 
   > 第二步,停止 java providers,可以 `kill -9 pid` 或 `CTRL+C`
   > 第三步,启动 java providers,启动命令和之前的一样
   > 
   > 此时再次通过:
   > 
   > ```shell
   > curl http://localhost:3000/hello
   > ```
   > 
   > 会得到输出:
   > 
   > ```
   > uuid:  invoke com.alibaba.dubbo.demo.DemoProvider#sayHello was error, Zookeeper Can not be find any agents
   > ```
   > 
   > 根据输出发现,node 和 ZK 之间的连接是通的,但是无法连接到 java providers
   > 
   > 此时重启 node,然后再次运行上面的 curl 命令,会发现 node 可以连接到 java providers,故障已经排除
   > 
   > 虽然上述复现步骤的报错信息和前面的 issue 中的 log 内容不同,不过不能排除前面的 log 有可能和问题并不对应,又或者该复现步骤反应了新的问题
   
   操作系统 : Centos7.2
   Node : 10.16.0
   Dubbo2.js : 2.3.9
   
   我本机可重现你的问题。
   查看源码
   ```js
   /**
      * 处理zookeeper的数据
      */
     private _handleZkClientOnData = (agentSet: Set<string>) => {
       //获取负载列表
       log(`get agent address:=> %O`, agentSet);
   
       //如果负载为空,也就是没有任何provider提供服务
       if (agentSet.size === 0) {
         this._status = STATUS.NO_AGENT;
         //将队列中的所有dubbo调用全调用失败
         const err = new ScheduleError('Can not be find any agents');
         this._queue.allFailed(err);
         traceErr(err);
         return;
       }
   
       //初始化dubboAgent
       this._dubboAgent.from(agentSet).subscribe({
         onConnect: this._handleOnConnect,
         onData: this._handleOnData,
         onClose: this._handleOnClose,
       });
     };
   ```
   是zookeeper返回的agent address为空会报`Can not be find any agents`错误。
   正如注释所示,注册中心服务为空,直接退出没得玩。
   还有服务剩余,还是有机会初始化dubboAgent。
   
   还有就是
   ```js
   this._queue.subscribe(this._handleQueueRequest);
   private _handleQueueRequest = requestId => {
       //record current status
       log(`handle requestId ${requestId}, current status: ${this._status}`);
   
       switch (this._status) {
         case STATUS.READY:
           //发起dubbo的调用
           this._handleDubboInvoke(requestId);
           break;
         case STATUS.PADDING:
           log('current scheduler was padding');
           break;
         case STATUS.NO_AGENT:
           this._handleFailed(
             requestId,
             new ScheduleError('Zookeeper Can not be find any agents'),
           );
           break;
         case STATUS.FAILED:
           this._handleFailed(
             requestId,
             new ScheduleError('ZooKeeper Could not be connected'),
           );
           break;
       }
     };
   ```
   处理任务队列的时候,状态为no_agent的时候,会报这个错误`Zookeeper Can not be find any agents`。
   第二步,停止 java providers时,其实你所有provide停止服务了。会导致`this._status = STATUS.NO_AGENT`,所以重启服务也没用。
   
   按照例子,你应该弄两个服务,先停止一个服务,再重启这个服务,dubbo-js还是会给你重连上。

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org