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.

IReader.HasMessageAvailableAsync incorrectly returns false when MessageIdInclusive=true

See original GitHub issue

HasMessageAvailableAsync as it always returns false for the last message only when StartMessageIdInclusive(true) is configured. This seems like a bug.

Is it expected that the C# test case below fails on the last assertion?

private async Task MessageIdInclusive_HasMessageAvailableAsync(string topic, PulsarClient client)
{
    await using var producer = await client.NewProducer().Topic(topic).CreateAsync();
    var previousMessageId = await producer.SendAsync(new byte[] { 1 });
    var expectedMessageId = await producer.SendAsync(new byte[] { 2 });

    // MessageId Exclusive works as expected
    await using var exclusiveReader = await client.NewReader().Topic(topic)
        .StartMessageId(previousMessageId).StartMessageIdInclusive(false).CreateAsync();
    var available = await exclusiveReader.HasMessageAvailableAsync();
    var actual = await exclusiveReader.ReadNextAsync();
    AssertEqual(expectedMessageId, actual);
    Assert.True(available);

    // MessageId Inclusive
    await using var inclusiveReader = await client.NewReader().Topic(topic)
        .StartMessageId(expectedMessageId).StartMessageIdInclusive(true).CreateAsync();
    available = await inclusiveReader.HasMessageAvailableAsync();
    actual = await inclusiveReader.ReadNextAsync();
    AssertEqual(expectedMessageId, actual);
    Assert.True(available); // <===== this assertion fails while a message was available??
}

The problem seems to be at line https://github.com/fsharplang-ru/pulsar-client-dotnet/blob/d80640ea82410479f60ff23f1e3b7f0d9554202c/src/Pulsar.Client/Internal/ConsumerImpl.fs#L132

When debugging my test case lastMessageIdInBroker and lastDequeuedMessageId are equal except for the Type, respectively Individual and Cumulative(0,null). So my test case passes if I modify MessageId.CompareTo and ignore the Type when comparing. I have no experience with the code base, so this is probably not a proper solution.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Lanayxcommented, Dec 15, 2020

Thanks, I’ll have a look tomorrow. In a while you can create a failing test in this file https://github.com/fsharplang-ru/pulsar-client-dotnet/blob/develop/tests/IntegrationTests/Reader.fs and send a PR to merge

0reactions
Lanayxcommented, Dec 27, 2020

You are welcome! Yes, it doesn’t need to change as it conforms to the Java version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

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