rocketmq icon indicating copy to clipboard operation
rocketmq copied to clipboard

[Bug] ack doesn't work after changeInvisibleDuration

Open niuhf0452 opened this issue 1 year ago • 7 comments

Before Creating the Bug Report

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

  • [x] I have searched the GitHub Issues and GitHub 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

RocketMQ Nameserver, Broker, Proxy ran in linux container with Podman Desktop on MacOS. Client ran on MacOS.

RocketMQ version

Broker 5.3.3, Client Java SDK 5.0.8.

JDK Version

JDK 21 Temurin-21.0.4+7

Describe the Bug

In particular sequence of operations, ack would not take effect nor throw exception.

Steps to Reproduce

  1. Create a topic that has 1 read queue and 1 write queue.
  2. Send 10 messages into the topic.
  3. Read the messages, for the 5th message, change its invisible duration and acknowledge it.
  4. Read the topic again, with the same consumer group.

What Did You Expect to See?

The acknowledged message would not be seen in the second read.

What Did You See Instead?

The acknowledged message was seen in the second read.

Additional Context

Test case:

rocketmq-test.zip

niuhf0452 avatar Jul 30 '25 04:07 niuhf0452

Found an old thread about the similar issue:

https://github.com/apache/rocketmq/discussions/6818

From cserwen's words, changeInvisibleDuration is not used for extending invisible duration. But I confirmed this view with Aliyun RocketMQ team, they are very sure that changeInvisibleDuration should be used for extending invisible duration.

niuhf0452 avatar Jul 30 '25 04:07 niuhf0452

when you change 5th message's invisible duration, rocketmq will do following things:

  1. ack the 5th msg,
  2. append a new ck message into timing wheel.

it means the old 5th message cant be acked after you change its invisible time.

GenerousMan avatar Jul 31 '25 03:07 GenerousMan

when you change 5th message's invisible duration, rocketmq will do following things:

  1. ack the 5th msg,
  2. append a new ck message into timing wheel.

it means the old 5th message cant be acked after you change its invisible time.

Then what is the correct way to extend invisible duration for a long running task?

Background: we can't decide how long a task would take. One example is importing data from excel file. The process time is relevant to the number of rows in the file. We built an event-driven application based on RocketMQ. The background processes are driven by MQ messages. That why we need a way to extend invisible duration.

niuhf0452 avatar Aug 01 '25 01:08 niuhf0452

When the first pop operation is used to get messages, the server generates an initial handle A. If the visibility timeout is extended via the change invisiable time operation, the server creates a new handle B and triggers a state transition (effectively invalidating A and activating B). At this point, attempting to acknowledge the message using the old handle A will fail, as only the new handle B is valid for acknowledgment

lizhimins avatar Aug 01 '25 02:08 lizhimins

When the first pop operation is used to get messages, the server generates an initial handle A. If the visibility timeout is extended via the change invisiable time operation, the server creates a new handle B and triggers a state transition (effectively invalidating A and activating B). At this point, attempting to acknowledge the message using the old handle A will fail, as only the new handle B is valid for acknowledgment

I understand. But please take a look at the source code, receiptHandle would be refreshed after changeInvisibleDuration. So in my case, I acknowledged to the new handle, not the old one.

https://github.com/apache/rocketmq-clients/blob/master/java/client/src/main/java/org/apache/rocketmq/client/java/impl/consumer/SimpleConsumerImpl.java#L288

Anyway, the point is not how it works, the point is what can we do.

My ask is:

  • Confirm if it's a bug, and fix it.
  • Or find a solution if it's not a bug.

niuhf0452 avatar Aug 01 '25 05:08 niuhf0452

This issue is stale because it has been open for 365 days with no activity. It will be closed in 3 days if no further activity occurs.

github-actions[bot] avatar Aug 02 '26 00:08 github-actions[bot]

This issue was closed because it has been inactive for 3 days since being marked as stale.

github-actions[bot] avatar Aug 06 '26 00:08 github-actions[bot]