azure-sdk-for-net icon indicating copy to clipboard operation
azure-sdk-for-net copied to clipboard

[BUG] PeekMessages/PeekMessage not receiving all messages after new ones were added to topic.

Open C485 opened this issue 2 years ago • 8 comments

Library name and version

Azure.Messaging.ServiceBus 7.11.1

Describe the bug

I've found several problem related to this methods. First description was provided in this bug report #30492 . It seams that messages that are sent after ServiceBusReceiver is created are not received.

Look at this screen, i've wrote example program to reproduce this issue (reproduction steps), total of 20 messages were sent but only 13 were received. image

To the example project i've added special flag "WithFix", with will force new instance of receiver to be created each tick of class with receiver mechanism. When "WithFix" is applied, everything "works as intended", of course that it will work because i'll pull all messages on startup.

I've tried all known to me ways to write this receiver (look at previous issue), waiting long time does nothing, PrefetchCount changes nothing, using PeekMessage as well.

Expected behavior

New messages should be received after instance of ServiceBusClient/ServiceBusReceiver was created. SequenceNumber should work as well.

Actual behavior

Only messages sent before instance of ServiceBusClient/ServiceBusReceiver are received (NOT ALWAYS!, sometimes 1-3 messages appear but never all of them). (NOT INCLUDED IN EXAMPLE CODE) SequenceNumber should work as well, now it seems that it's skipped when EnablePartitioning/EnableBatchedOperations is enabled .

Reproduction Steps

Code available here: https://github.com/C485/ServiceBusPeekMessagesBug Just put connection string to SB with ALL RIGHTS! Start the program, there will be 2 hidden exceptions from GetTopicAsync and GetSubscriptionAsync, this is expected (lazy developer syndrome).

Environment

.Net 6 Windows

C485 avatar Nov 16 '22 16:11 C485

Thank you for your feedback. Tagging and routing to the team member best able to assist.

jsquire avatar Nov 16 '22 22:11 jsquire

@jsquire is @JoshLove-msft alive? it's been like 2 months

C485 avatar Jan 05 '23 14:01 C485

Sorry for the delay - I am, in fact, alive and well. I will take a look at this today.

JoshLove-msft avatar Jan 05 '23 18:01 JoshLove-msft

Thanks for the great repro - it looks like this is related to the fact that the topic is partitioned. With partitioned entities, the top 16 bits of the sequence number of a message correspond to the partition. When peeking we increment the last peeked sequence number internally and use that in subsequent calls from the same client. Because of the way the sequence number is generated for partitioned entities, the sequence number is not strictly increasing for new messages. I will need to reach out to the service team for guidance on what we can do here to improve the experience.

JoshLove-msft avatar Jan 05 '23 19:01 JoshLove-msft

I've confirmed with the service team that this is a current limitation of peeking partitioned entities. To fix this, service side changes are required. From the library side, I will update our troubleshooting guide to mention that peeking doesn't really work reliably for partitioned entities.

JoshLove-msft avatar Jan 05 '23 20:01 JoshLove-msft

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @shankarsama, @DorothySun216, @EldertGrootenboer, @saglodha.

Issue Details

Library name and version

Azure.Messaging.ServiceBus 7.11.1

Describe the bug

I've found several problem related to this methods. First description was provided in this bug report #30492 . It seams that messages that are sent after ServiceBusReceiver is created are not received.

Look at this screen, i've wrote example program to reproduce this issue (reproduction steps), total of 20 messages were sent but only 13 were received. image

To the example project i've added special flag "WithFix", with will force new instance of receiver to be created each tick of class with receiver mechanism. When "WithFix" is applied, everything "works as intended", of course that it will work because i'll pull all messages on startup.

I've tried all known to me ways to write this receiver (look at previous issue), waiting long time does nothing, PrefetchCount changes nothing, using PeekMessage as well.

Expected behavior

New messages should be received after instance of ServiceBusClient/ServiceBusReceiver was created. SequenceNumber should work as well.

Actual behavior

Only messages sent before instance of ServiceBusClient/ServiceBusReceiver are received (NOT ALWAYS!, sometimes 1-3 messages appear but never all of them). (NOT INCLUDED IN EXAMPLE CODE) SequenceNumber should work as well, now it seems that it's skipped when EnablePartitioning/EnableBatchedOperations is enabled .

Reproduction Steps

Code available here: https://github.com/C485/ServiceBusPeekMessagesBug Just put connection string to SB with ALL RIGHTS! Start the program, there will be 2 hidden exceptions from GetTopicAsync and GetSubscriptionAsync, this is expected (lazy developer syndrome).

Environment

.Net 6 Windows

Author: C485
Assignees: JoshLove-msft
Labels:

Service Bus, Service Attention, Client, customer-reported, question, needs-team-attention

Milestone: -

ghost avatar Jan 05 '23 20:01 ghost

We have reassigned an engineer to look further into this issue. We will update this issue when we have more information.

EldertGrootenboer avatar Oct 13 '23 18:10 EldertGrootenboer

Thank you for your feedback. We have brought this item in our current planning, once we have more information around this, we will update this thread.

EldertGrootenboer avatar Apr 26 '24 17:04 EldertGrootenboer