Azure / azure-uamqp-python

AMQP 1.0 client library for Python
MIT License
57 stars 47 forks source link

_link_error is not cleaned up when multiples links are sharing session #149

Closed yunhaoling closed 2 years ago

yunhaoling commented 4 years ago

Describe the bug

When multiples links (sender/receiver) are sharing the same session, if one of these links gets into error state, the uamqp.Session would mark self._link_error: https://github.com/Azure/azure-uamqp-python/blob/master/uamqp/session.py#L48

However, this behavior blocks pending links to establish the connection. Because in _state_changed of sender/receiver, it will check self._session._link_error and find error is not None -- the error is caused by the last link establishment. https://github.com/Azure/azure-uamqp-python/blob/master/uamqp/sender.py#L170

The variable session._link_error is not cleaned up when new links want to establish connection.

To Reproduce Steps to reproduce the behavior:

Using ServiceBus write-only connection string for a queue:

    with client:

        try:
            with client.get_queue_receiver(QUEUE_NAME) as receiver:
                messages = receiver.receive(max_batch_size=1, timeout=1)
        except Exception as e:
            assert isinstance(e, ServiceBusError)

        # hotfix, reset _link_error to None before next link establishment
        # client._connection.auth._session._link_error = None 

        with client.get_queue_sender(QUEUE_NAME) as sender:
            sender.send(Message("test"))
            try:
                sender.send("cat")
            except Exception as e:
                assert isinstance(e, ServiceBusError)