You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by pe...@apache.org on 2021/06/26 12:16:29 UTC

[pulsar] 02/04: Fix hasMessageAvailable return true but can't read message (#10414)

This is an automated email from the ASF dual-hosted git repository.

penghui pushed a commit to branch branch-2.7
in repository https://gitbox.apache.org/repos/asf/pulsar.git

commit 81cbc960055c1480072308b776ce15ac055c237c
Author: feynmanlin <fe...@tencent.com>
AuthorDate: Tue May 4 10:39:35 2021 +0800

    Fix hasMessageAvailable return true but can't read message (#10414)
    
    ### Motivation
    
    I temporarily fixed this problem in PR https://github.com/apache/pulsar/pull/10190.
    Now we have found a better way, this way can avoid the seek, then avoid trigger another reconnection.
    Thank you @codelipenghui  to troubleshoot this issue with me all night.
    
    We have added a lot of log and found that this issue is caused by some race condition problems. Here is the first reason:
    https://github.com/apache/pulsar/blob/f2d72c9fc13a33df584ec1bd96a4c147774b858d/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java#L1808-L1818
    Now we have an acknowledgmentsGroupingTracker to filter duplicate messages, and this Tracker will be cleaned up after seek.
    
    However, it is possible that the connection is ready and Broker has pushed message, but `acknowledgmentsGroupingTracker.flushAndClean(); ` has not been executed yet.
    
    Finally hasMessageAvailableAsync returns true, but the message cannot be read because it is filtered by the acknowledgmentsGroupingTracker
    
    
    ### Modifications
    clean the tracker when connection was open
    
    ### Verifying this change
    
    
    (cherry picked from commit f69a03b28d29689eaf910e0b99994fa250adb213)
---
 .../src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java      | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java
index 2eefb5b..479ddce 100644
--- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java
+++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java
@@ -839,6 +839,9 @@ public class ConsumerImpl<T> extends ConsumerBase<T> implements ConnectionHandle
         log.info("[{}][{}] Subscribing to topic on cnx {}, consumerId {}", topic, subscription, cnx.ctx().channel(),consumerId);
 
         long requestId = client.newRequestId();
+        if (duringSeek.get()) {
+            acknowledgmentsGroupingTracker.flushAndClean();
+        }
 
         int currentSize;
         synchronized (this) {