pulsar: [Bug] Delayed message delivery receive duplicate messages when unload topic

Search before asking

  • I searched in the issues and found nothing similar.

Version

2.7.5 / 2.8.4 /master

Minimal reproduce step

  1. Run the code for 20 minutes
public static void main(String[] args) {
        String url = "pulsar://10.98.242.210:6650";
        String t = "persistent://components/test/test_deliver";
        new Thread(() -> {
            try {
                PulsarClient client = PulsarClient.builder()
                    .serviceUrl(url)
                    .ioThreads(1)
                    .listenerThreads(2)
                    .build();
                Producer<String> producerA = client.newProducer(Schema.STRING)
                    .topic(t)
                    .producerName("test")
                    .create();
                Random random = new Random();
                while (true) {
                    String message = String.valueOf(System.currentTimeMillis());
                    producerA.newMessage(Schema.STRING).value(message).deliverAfter(random.nextInt(30), TimeUnit.MINUTES).send();
                    Thread.sleep(10L);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }).start();
        Set<String> stringSet = new ConcurrentHashSet<>();
        try {
            PulsarClient client = PulsarClient.builder()
                .serviceUrl(url)
                .ioThreads(1)
                .listenerThreads(2)
                .build();
            Consumer consumer = client.newConsumer(Schema.STRING)
                .topic(t)
                .subscriptionName("frozen")
                .subscriptionType(SubscriptionType.Shared)
                .subscribe();
            while (true) {
                Message<String> message = consumer.receive();
                if (stringSet.contains(message.getValue())) {
                    log.info("duplicate messages thread={} message={}", Thread.currentThread().getName(), message.getValue());
                } else {
                    stringSet.add(message.getValue());
                }
                consumer.acknowledge(message);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
  1. After 20 minutes, execute unload cmd:
bin/pulsar-admin topics unload persistent://components/test/test_deliver
  1. See consumer log, duplicate messages

What did you expect to see?

no duplicate messages

What did you see instead?

duplicate messages

Anything else?

No response

Are you willing to submit a PR?

  • I’m willing to submit a PR!

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

@dao-jun I confirm it dose not contain non-delayed delivery message. In my program any message has more than 5 minute delay time. Sad, I choose Pulsar because it supports delayed messages. Any plan for this bug?

I guess your topic have non-delayed delivery messages and delay delivery messages, if your topic only have delayed delivery messages, it will be work. As I marked before, it’s the conflicts between cursor.readEntries and cursor.asyncReplayEntries, one for delayed messages, another fro non-delayed delivery messages. We don’t have a suitable solution yet to solve the problem. @SennoYuki

enable AckWithResponse, the consumer will wait until broker received the ack

cc @coderzc since you’re working on delay message heavily recently, can you help with this issue to see if it’s a usage issue?