Skip to content

Servicebus receive_messages limited when called in loop #40156

Open
@kegs-equinor

Description

@kegs-equinor
  • Package Name: azure-servicebus
  • Package Version: 7.14.1
  • Operating System: All (SDK Issue)
  • Python Version: 3.12.3

Describe the bug

When calling receiver.receive_messages(max_message_count=100) in a loop, the maximum received messages will never be higher than the amount received in the last call.

To Reproduce
Steps to reproduce the behavior:

receiver = client.get_queue_receiver()
with receiver:
  # The queue originally contains 100 messages before starting
  msgs = receiver.receive_messages(max_message_count=100)
  print(len(msgs))  # 100
  # Add a single message to the queue
  msgs = receiver.receive_messages(max_message_count=100)
  print(len(msgs))  # 1
  # Add 100 messages to the queue
  msgs = receiver.receive_messages(max_message_count=100)
  print(len(msgs)) #  1
  msgs = receiver.receive_messages(max_message_count=100)
  print(len(msgs)) #  1
  msgs = receiver.receive_messages(max_message_count=100)
  print(len(msgs)) #  1
  ...

Expected behavior
The amount of messages received should not depend on how many were received in the previous call. I know that the receive call may return early with less that all the messages, but it should not be capped at the result of the previous call.

Additional context
I am pretty sure that the azure.servicebus._pyamqp.link Link.flow is the problem:

    def flow(self, *, link_credit: Optional[int] = None, **kwargs: Any) -> None:
        # Given the desired link credit `link_credit`, the link credit sent via
        # FlowFrame is calculated as follows: The link credit to flow on the wire
        # `self.current_link_credit` is the desired link credit
        # `link_credit` minus the current link credit on the wire `self.total_link_credit`.
        self.current_link_credit = link_credit - self.total_link_credit if link_credit is not None else self.link_credit

        # If the link credit to flow is greater than 0 (i.e the desired link credit is greater than
        # the current link credit on the wire), then we will send a flow to issue more link credit.
        # Otherwise link credit on the wire is sufficient.
        if self.current_link_credit > 0:
            # Calculate the total link credit on the wire, by adding the credit we will flow to the total link credit.
            self.total_link_credit = (
                self.current_link_credit + self.total_link_credit if link_credit is not None else self.link_credit
            )
            self._outgoing_flow(**kwargs)

This function assumes that when setting the flow to the sender is cumulative. It is not

Image

Metadata

Metadata

Labels

ClientThis issue points to a problem in the data-plane of the library.MessagingMessaging crewService Buscustomer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK teamquestionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions