azure-sdk-for-python: ServiceBusConnectionError after running idle

  • azure-servicebus:
  • 7.12.1:
  • Azure Container Apps:
  • 3.12:

Describe the bug We are getting the following error while receiving messages from Service Bus: azure.servicebus.exceptions.ServiceBusConnectionError: Cannot read frame due to exception: [Errno 104] Connection reset by peer. Error condition: amqp:socket-error.

We observe this behavior when there are no messages in the subscription and you keep the app running.

To Reproduce There are no exact steps to reproduce this issue. It happens inconsistently. We observe this happening when there are no messages in the subscription, and the app has been running for a long duration.

Expected behavior The SDK should retry with some delay.

Logs

2024-07-02 17:57:17,088 - azure.servicebus._pyamqp.aio._transport_async - DEBUG - Transport read failed: ConnectionResetError(104, 'Connection reset by peer')
2024-07-02 17:57:17,088 - azure.servicebus._pyamqp.aio._cbs_async - DEBUG - CBS status check: state == <CbsAuthState.OK: 0>, expired == False, refresh required == False
2024-07-02 17:57:17,088 - azure.servicebus.aio._base_handler_async - INFO - AMQP error occurred: (AMQPConnectionError('Error condition: ErrorCondition.SocketError\n Error Description: Can not read frame due to exception: [Errno 104] Connection reset by peer')), condition: (<ErrorCondition.SocketError: b'amqp:socket-error'>), description: ('Can not read frame due to exception: [Errno 104] Connection reset by peer').
2024-07-02 17:57:17,088 - azure.servicebus._pyamqp.aio._link_async - DEBUG - -> DetachFrame(handle=3, closed=True, error=None)
2024-07-02 17:57:17,089 - azure.servicebus._pyamqp.aio._link_async - INFO - An error occurred when detaching the link: AMQPConnectionError('Error condition: ErrorCondition.SocketError\n Error Description: Can not read frame due to exception: [Errno 104] Connection reset by peer')
2024-07-02 17:57:17,089 - azure.servicebus._pyamqp.aio._link_async - INFO - Link state changed: <LinkState.ATTACHED: 3> -> <LinkState.DETACHED: 0>
2024-07-02 17:57:17,089 - azure.servicebus._pyamqp.aio._link_async - DEBUG - -> DetachFrame(handle=2, closed=True, error=None)
2024-07-02 17:57:17,089 - azure.servicebus._pyamqp.aio._link_async - INFO - An error occurred when detaching the link: AMQPConnectionError('Error condition: ErrorCondition.SocketError\n Error Description: Can not read frame due to exception: [Errno 104] Connection reset by peer')
2024-07-02 17:57:17,089 - azure.servicebus._pyamqp.aio._link_async - INFO - Link state changed: <LinkState.ATTACHED: 3> -> <LinkState.DETACHED: 0>
2024-07-02 17:57:17,089 - azure.servicebus._pyamqp.aio._management_link_async - INFO - Management link receiver state changed: <LinkState.ATTACHED: 3> -> <LinkState.DETACHED: 0>
2024-07-02 17:57:17,089 - azure.servicebus._pyamqp.aio._link_async - DEBUG - -> DetachFrame(handle=1, closed=True, error=None)
2024-07-02 17:57:17,089 - azure.servicebus._pyamqp.aio._link_async - INFO - An error occurred when detaching the link: AMQPConnectionError('Error condition: ErrorCondition.SocketError\n Error Description: Can not read frame due to exception: [Errno 104] Connection reset by peer')
2024-07-02 17:57:17,089 - azure.servicebus._pyamqp.aio._link_async - INFO - Link state changed: <LinkState.ATTACHED: 3> -> <LinkState.DETACHED: 0>
2024-07-02 17:57:17,089 - azure.servicebus._pyamqp.aio._management_link_async - INFO - Management link sender state changed: <LinkState.ATTACHED: 3> -> <LinkState.DETACHED: 0>
2024-07-02 17:57:17,089 - azure.servicebus._pyamqp.aio._session_async - DEBUG - -> EndFrame(error=None)
2024-07-02 17:57:17,089 - azure.servicebus._pyamqp.aio._session_async - INFO - An error occurred when ending the session: AMQPConnectionError('Error condition: ErrorCondition.SocketError\n Error Description: Can not read frame due to exception: [Errno 104] Connection reset by peer')
2024-07-02 17:57:17,089 - azure.servicebus._pyamqp.aio._session_async - INFO - Session state changed: <SessionState.MAPPED: 3> -> <SessionState.UNMAPPED: 0>
2024-07-02 17:57:17,089 - azure.servicebus._pyamqp.aio._connection_async - DEBUG - -> CloseFrame(error=None)
2024-07-02 17:57:17,089 - azure.servicebus._pyamqp.aio._connection_async - INFO - An error occurred when closing the connection: AMQPConnectionError('Error condition: ErrorCondition.SocketError\n Error Description: Can not read frame due to exception: [Errno 104] Connection reset by peer')
2024-07-02 17:57:17,089 - azure.servicebus._pyamqp.aio._connection_async - INFO - Connection state changed: <ConnectionState.OPENED: 9> -> <ConnectionState.END: 13>
2024-07-02 17:57:17,883 - azure.servicebus.aio._base_handler_async - INFO - 'servicebus.pysdk-22e5f6be' operation has exhausted retry. Last exception: ServiceBusConnectionError('Can not read frame due to exception: [Errno 104] Connection reset by peer Error condition: amqp:socket-error.').

this is the code snippet inside a package

class SubscriptionListener:
    def __init__(self, connection_string: str, topic_name: str, subscription_name: str, max_concurrent_tasks=5):
        self._connection_string = connection_string
        self._topic_name=topic_name
        self._subscription_name = subscription_name
        self._message_handlers: Dict[type, Callable] = {}

    def add_message_handler(self, message_type: type, handler: Callable):
        self._message_handlers[message_type] = handler

    async def receive_messages(self):
        async with ServiceBusClient.from_connection_string(self._connection_string,logging_enable=True) as client:
            async with client.get_subscription_receiver(topic_name=self._topic_name,subscription_name= self._subscription_name) as receiver:
                async for message in receiver:
                    await self._process_and_complete_message(receiver, message)    

and this is code snippet inside our API that invoke the above

service_bus_receiver = SubscriptionListener(conn_str, topic_name,subscription_name)
service_bus_receiver.add_message_handler(ExtractionMessage, extraction_message_handler.handle)
await service_bus_receiver.receive_messages()

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19 (7 by maintainers)

Most upvoted comments

@swathipil I have added the logs. I tried to color the start and end of the error in yellow.

Is there any other activity happening on your VNET (heavier than usual) that could be causing issues? -> Nothing as far as we know.