beijixing1745 opened a new issue, #6546:
URL: https://github.com/apache/rocketmq/issues/6546

   **BUG REPORT**
   
   1. operate detail :
   
   win10 内存 32G rocketmq 4.9.4、4.9.5都有问题
   (1)set env
   set NAMESRV_ADDR=10.0.24.108:9876
   set JAVA_HOME=C:\language\java\jdk1.8.0_251
   set ROCKETMQ_HOME=D:\work\server\queue\rocketmq-all-4.9.5-bin-release
   (2)启动 mqnamesrv.cmd,mqbroker.cmd
   mqnamesrv.cmd
   Java HotSpot(TM) 64-Bit Server VM warning: Using the DefNew young collector 
with the CMS collector is deprecated and will likely be removed in a future 
release
   Java HotSpot(TM) 64-Bit Server VM warning: UseCMSCompactAtFullCollection is 
deprecated and will likely be removed in a future release.
   The Name Server boot success. serializeType=JSON
   
   mqbroker.cmd -n 10.0.24.108:9876 autoCreateTopicEnable=true -c 
../conf/broker.conf
   The broker[broker-a, 10.0.24.108:10911] boot success. serializeType=JSON and 
name server is 10.0.24.108:9876
   
   (3)本机执行 mqadmin statsAll -n 10.0.24.108:9876
   mqadmin statsAll -n 10.0.24.108:9876
   org.apache.rocketmq.tools.command.SubCommandException: StatsAllSubCommand 
command failed
           at 
org.apache.rocketmq.tools.command.stats.StatsAllSubCommand.execute(StatsAllSubCommand.java:202)
           at 
org.apache.rocketmq.tools.command.MQAdminStartup.main0(MQAdminStartup.java:149)
           at 
org.apache.rocketmq.tools.command.MQAdminStartup.main(MQAdminStartup.java:100)
   Caused by: org.apache.rocketmq.remoting.exception.RemotingConnectException: 
connect to [10.0.24.108:9876] failed
           at 
org.apache.rocketmq.remoting.netty.NettyRemotingClient.getAndCreateNameserverChannel(NettyRemotingClient.java:458)
           at 
org.apache.rocketmq.remoting.netty.NettyRemotingClient.getAndCreateChannel(NettyRemotingClient.java:413)
           at 
org.apache.rocketmq.remoting.netty.NettyRemotingClient.invokeSync(NettyRemotingClient.java:382)
           at 
org.apache.rocketmq.client.impl.MQClientAPIImpl.getTopicListFromNameServer(MQClientAPIImpl.java:1426)
           at 
org.apache.rocketmq.tools.admin.DefaultMQAdminExtImpl.fetchAllTopicList(DefaultMQAdminExtImpl.java:280)
           at 
org.apache.rocketmq.tools.admin.DefaultMQAdminExt.fetchAllTopicList(DefaultMQAdminExt.java:231)
           at 
org.apache.rocketmq.tools.command.stats.StatsAllSubCommand.execute(StatsAllSubCommand.java:172)
           ... 2 more
   
   
   3. 同样版本4.9.4在有的机器没有问题,参考 https://github.com/apache/rocketmq/pull/6279/files:
   用4.9.4的源码调试 
org.apache.rocketmq.remoting.netty.NettyRemotingClient,函数invokeSync
   
   修改内容
   
   ```
   public RemotingCommand invokeSync(String addr, final RemotingCommand 
request, long timeoutMillis)
           throws InterruptedException, RemotingConnectException, 
RemotingSendRequestException, RemotingTimeoutException {
   。。。。。。
    final Channel channel = this.getAndCreateChannel(addr);
   String channelRemoteAddr = RemotingHelper.parseChannelRemoteAddr(channel);
   。。。。。。
     doBeforeRpcHooks(channelRemoteAddr, request);
   。。。。。。
   doAfterRpcHooks(channelRemoteAddr, request, response);
   ```
   
   函数修改后
   ```
   public RemotingCommand invokeSync(String addr, final RemotingCommand 
request, long timeoutMillis)
           throws InterruptedException, RemotingConnectException, 
RemotingSendRequestException, RemotingTimeoutException {
           long beginStartTime = System.currentTimeMillis();
           final Channel channel = this.getAndCreateChannel(addr);
           String channelRemoteAddr = 
RemotingHelper.parseChannelRemoteAddr(channel);
           if (channel != null && channel.isActive()) {
               try {
                   doBeforeRpcHooks(channelRemoteAddr, request);
                   long costTime = System.currentTimeMillis() - beginStartTime;
                   if (timeoutMillis < costTime) {
                       throw new RemotingTimeoutException("invokeSync call the 
addr[" + addr + "] timeout");
                   }
                   RemotingCommand response = this.invokeSyncImpl(channel, 
request, timeoutMillis - costTime);
                   doAfterRpcHooks(channelRemoteAddr, request, response);
                   return response;
               } catch (RemotingSendRequestException e) {
                   log.warn("invokeSync: send request exception, so close the 
channel[{}]", addr);
                   this.closeChannel(addr, channel);
                   throw e;
               } catch (RemotingTimeoutException e) {
                   if (nettyClientConfig.isClientCloseSocketIfTimeout()) {
                       this.closeChannel(addr, channel);
                       log.warn("invokeSync: close socket because of timeout, 
{}ms, {}", timeoutMillis, addr);
                   }
                   log.warn("invokeSync: wait response timeout exception, the 
channel[{}]", addr);
                   throw e;
               }
           } else {
               this.closeChannel(addr, channel);
               throw new RemotingConnectException(addr);
           }
       }
   ```
   
   按修改后的内容运行不会出现异常。调试中发现异常的原因为执行到以下代码抛了异常
   ```
    doBeforeRpcHooks(channelRemoteAddr, request);
     long costTime = System.currentTimeMillis() - beginStartTime;
                   if (timeoutMillis < costTime) {
                       throw new RemotingTimeoutException("invokeSync call the 
addr[" + addr + "] timeout");
                   }
   ```
   
   是否因为本机有虚拟多网卡等情况时用Channel channel 执行 doBeforeRpcHooks(channel, 
request);花费的时间比用doBeforeRpcHooks(channelRemoteAddr, 
request);花费时间长,导致timeoutMillis < costTime为true ,抛出了异常?


-- 
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]

Reply via email to