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

   ### Before Creating the Bug Report
   
   - [x] I found a bug, not just asking a question, which should be created in 
[GitHub Discussions](https://github.com/apache/rocketmq/discussions).
   
   - [x] I have searched the [GitHub 
Issues](https://github.com/apache/rocketmq/issues) and [GitHub 
Discussions](https://github.com/apache/rocketmq/discussions)  of this 
repository and believe that this is not a duplicate.
   
   - [x] I have confirmed that this bug belongs to the current repository, not 
other repositories of RocketMQ.
   
   
   ### Runtime platform environment
   
   centos7
   
   ### RocketMQ version
   
   5.3.1及以上
   
   ### JDK Version
   
   jdk8
   
   ### Describe the Bug
   
   
       public Message request(final Message msg,
           long timeout) throws RequestTimeoutException, MQClientException, 
RemotingException, MQBrokerException, InterruptedException {
           long beginTimestamp = System.currentTimeMillis();
           prepareSendRequest(msg, timeout);
           final String correlationId = 
msg.getProperty(MessageConst.PROPERTY_CORRELATION_ID);
   
           try {
               final RequestResponseFuture requestResponseFuture = new 
RequestResponseFuture(correlationId, timeout, null);
               
RequestFutureHolder.getInstance().getRequestFutureTable().put(correlationId, 
requestResponseFuture);
   
               long cost = System.currentTimeMillis() - beginTimestamp;
               this.sendDefaultImpl(msg, CommunicationMode.ASYNC, new 
SendCallback() {
                   @Override
                   public void onSuccess(SendResult sendResult) {
                       requestResponseFuture.setSendRequestOk(true);
                       // 
注意当broker写入成功后响应客户端,该方法会被调起,导致waitResponse直接返回,此时reply消息可能还未到达。应该将这行代码删除。
                       requestResponseFuture.acquireCountDownLatch();
                   }
   
                   @Override
                   public void onException(Throwable e) {
                       requestResponseFuture.setSendRequestOk(false);
                       requestResponseFuture.putResponseMessage(null);
                       requestResponseFuture.setCause(e);
                   }
               }, timeout - cost);
   
               return waitResponse(msg, timeout, requestResponseFuture, cost);
           } finally {
               
RequestFutureHolder.getInstance().getRequestFutureTable().remove(correlationId);
           }
       }
   
   
这个方法会导致rpc调用还未等到超时时间就抛出RequestTimeoutException异常,原因:注意当broker写入成功后响应客户端,SendCallback.onSuccess方法会被调起,requestResponseFuture的锁提前释放,从而导致waitResponse直接返回,此时reply消息可能还未到达。
   
   
   ### Steps to Reproduce
   
   运行example工程下只启动RequestProducer,不启动ResponseConsumer,将超时时间设置为60s, 
大概1s以内就会抛出描述中的异常。
   
   ### What Did You Expect to See?
   
   该方法用于实现rpc调用,期望在超时时间到达之前或者reply消息到达之前,不应该直接返回。
   
   ### What Did You See Instead?
   
   期望在超时时间到达之前或者reply消息到达之后,才返回相应结果。
   
   ### Additional Context
   
   _No response_


-- 
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: commits-unsubscr...@rocketmq.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to