Skip to content

[Bug] Bug title #9319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 tasks done
yyh1987299 opened this issue Apr 8, 2025 · 0 comments
Open
3 tasks done

[Bug] Bug title #9319

yyh1987299 opened this issue Apr 8, 2025 · 0 comments

Comments

@yyh1987299
Copy link

Before Creating the Bug Report

  • I found a bug, not just asking a question, which should be created in GitHub Discussions.

  • I have searched the GitHub Issues and GitHub Discussions of this repository and believe that this is not a duplicate.

  • 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@yyh1987299 and others