The phenomenon of the bug:
When consumers was killed and restarted frequently, some messages could not be consumed by consumer but they were still in pending messages.
When consumer consumes messages in transaction, it sends ack command and transaction commit command separately, if the consumer was killed between ack command and transaction commit command, in other words the Broker only received the ack command but did not receive the transaction commit command, this lead to the message in PrefetchSubscription’s dispatched list was set ack true, but was not removed from dispatched list. When the consumer was killed, Queue#removeSubscription() was called, in this method, PrefetchSubscription#remove() was called to put PrefetchSubscription’s pending list and dispatched list to Queue’s redeliveredWaitingDispatch list. After that, when Queue#doDispatch() was called, the redeliveredWaitingDispatch list was transferred to Queue#doActualDispatch () method to dispatch the messages to consumer again. In Queue#doActualDispatch () method, if all consumers isFull() method returns true, the target is null and the expression “interestCount > 0” become the only condition to judge if the message should be put back to the redeliveredWaitingDispatch, but now the message’s isAcked() method returns true, this lead to interestCount is 0, and then the message was not put back to redeliveredWaitingDispatch, but it was not consumed and was still in pagedInMessages.
In PrefetchSubscription#remove() method, set ack status to false for all messages in dispatched list. The code as follows:
The solution can solve the problem, I want to know if the solution can lead to other problems.