question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Repeated messages of shared dispatcher

See original GitHub issue

Describe the bug Recently I found the C++ tests BasicEndToEndTest.testPatternMultiTopicsConsumerPubSub and BasicEndToEndTest.testpatternMultiTopicsHttpConsumerPubSub became flaky. Eventually I found it’s caused by the duplicated messages.

To Reproduce

First, start a standalone with latest master.

Then, run the following Java test.

    @Test(invocationCount = 10)
    public void test() throws Exception {
        @Cleanup final PulsarAdmin admin = PulsarAdmin.builder().serviceHttpUrl("http://127.0.0.1:8080").build();
        final String topicBase = "persistent://public/default/my-topic-" + System.currentTimeMillis();
        for (int i = 0; i < 3; i++) {
            admin.topics().createPartitionedTopic(topicBase + "-" + i, i + 2);
        }
        @Cleanup final PulsarClient client = PulsarClient.builder().serviceUrl("pulsar://localhost:6650").build();
        final Consumer<byte[]> consumer = client.newConsumer()
                .topicsPattern(topicBase + ".*")
                .subscriptionName("sub")
                .receiverQueueSize(10)
                .subscriptionType(SubscriptionType.Shared)
                .subscribe();
        final int numMessages = 100;
        for (int i = 0; i < 3; i++) {
            final Producer<byte[]> producer = client.newProducer()
                    .topic(topicBase + "-" + i)
                    .messageRoutingMode(MessageRoutingMode.RoundRobinPartition)
                    .create();
            for (int j = 0; j < numMessages; j++) {
                producer.send(("msg-content-" + i + "-" + j).getBytes());
            }
        }
        int numReceived = 0;
        while (true) {
            final Message<byte[]> msg = consumer.receive(1, TimeUnit.SECONDS);
            if (msg == null) {
                break;
            }
            numReceived++;
        }
        Assert.assertEquals(numReceived, numMessages * 3);
    }

Sometimes it failed. (You can add more logs or debugged code to see the received messages of all partitions)

Expected behavior The tests should always succeed.

Screenshots The failure in my local env.

截屏2022-07-26 23 00 19 image

Additional context Adding some logs into C++ tests could make tests more stable to pass. And the Java test looks less flaky than the C++ tests.

After applying dispatcherDispatchMessagesInSubscriptionThread=false in conf/standalone.conf, the Java test could pass even if invocationCount = 50. Changing the subscription type to Exclusive also works.

image

From the test result, we can see the bug was introduced from https://github.com/apache/pulsar/pull/16603 that we should not run sendMessagesToConsumers in another thread.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
eolivellicommented, Jul 27, 2022

in #16603 I had to change a test that was failing in a similar way. but the test was missing a “acknowledge(message)” so I thought that the test was wrong.

https://github.com/apache/pulsar/pull/16603/files#diff-33303e92b2d03115c1bde9ad3af39f9127f6a25270855fb5b5c2eb7c3db74e50R281

I will revert the change to the test and add your new test case

0reactions
tisonkuncommented, Aug 9, 2022

It seems the exception is timeout instead of unexpected result, reported at https://github.com/apache/pulsar/issues/17008.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[GitHub] [pulsar] BewareMyPower commented on a diff in pull ...
[GitHub] [pulsar] BewareMyPower commented on a diff in pull request #16812: Issue 16802: fix Repeated messages of shared dispatcher.
Read more >
11 Configuring Dispatchers
The dispatcher directs multiple incoming network session requests to a common queue. An idle shared server process from a shared pool of server...
Read more >
Dispatchers (Scala) - Documentation - Akka
The 'ThreadBasedDispatcher' binds a dedicated OS thread to each specific Actor. The messages are posted to a 'LinkedBlockingQueue' which feeds ...
Read more >
Event Queue and Message Dispatch
Use a dispatch loop to repeatedly dispatch messages. You may start several dispatch loops in separate threads to take advantage of multi-core processors....
Read more >
Design pattern for handling multiple message types
The basic idea is to register a set of handlers that dispatch the received messages to the handler for processing based on the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found