Skip to content

ServiceBus async AutoLockRenewer crashes on disposal if no messages have been registered #19642

Description

  • Package Name: azure-servicebus
  • Package Version: 7.3.0
  • Operating System: Mac OSx
  • Python Version: 3.8.7

Describe the bug
I am using the async version of AutoLockRenewer. I have noticed that if I create it but I do not register a message (either directly or via a receiver), then I get an exception when it is disposed.

To Reproduce
Steps to reproduce the behavior: see the following code


import os
import asyncio
from distutils.util import strtobool
from azure.servicebus.aio import ServiceBusClient, AutoLockRenewer

CONNECTION_STR = os.environ['SERVICE_BUS_CONNECTION_STR']
QUEUE_NAME = os.environ["SERVICE_BUS_QUEUE_NAME"]

async def code_failing():

    servicebus_client = ServiceBusClient.from_connection_string(conn_str=CONNECTION_STR)

    async with servicebus_client:

        print('context, register via receiver')
        try:
            async with AutoLockRenewer(max_lock_renewal_duration=20*60) as renewer:

                async with servicebus_client.get_queue_receiver(queue_name=QUEUE_NAME, auto_lock_renewer=renewer) as receiver:
                    _ = await receiver.receive_messages(max_message_count=10, max_wait_time=5)
        except Exception as e:
            print(e)

        print('context, register explicitly')
        try:
            async with AutoLockRenewer(max_lock_renewal_duration=20*60) as renewer:

                async with servicebus_client.get_queue_receiver(queue_name=QUEUE_NAME, ) as receiver:
                    _ = await receiver.receive_messages(max_message_count=10, max_wait_time=5)
        except Exception as e:
            print(e)

        print('no context, register via receiver')
        try:
            renewer = AutoLockRenewer(max_lock_renewal_duration=20*60)

            async with servicebus_client.get_queue_receiver(queue_name=QUEUE_NAME, auto_lock_renewer=renewer) as receiver:
                _ = await receiver.receive_messages(max_message_count=10, max_wait_time=5)

            await renewer.close()
        except Exception as e:
            print(e)


        print('no context, register explicitly')
        try:
            renewer = AutoLockRenewer(max_lock_renewal_duration=20*60)

            async with servicebus_client.get_queue_receiver(queue_name=QUEUE_NAME) as receiver:
                _ = await receiver.receive_messages(max_message_count=10, max_wait_time=5)

            await renewer.close()
        except Exception as e:
            print(e)

if __name__ == '__main__':

    asyncio.run(code_failing())


Expected behavior
The object should be cleanly disposed. Instead I get:

10:57 $ env $(grep -v '^#' env  | xargs -0)  python3 autolock-bug.py 
context, register via receiver
Set of coroutines/Futures is empty.
context, register explicitly
Set of coroutines/Futures is empty.
no context, register via receiver
Set of coroutines/Futures is empty.
no context, register explicitly
Set of coroutines/Futures is empty.

each exception is like:

Traceback (most recent call last):
  File "autolock-bug.py", line 32, in <module>
    asyncio.run(code_failing())
  File "/Users/aca286/.pyenv/versions/3.8.7/lib/python3.8/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/Users/aca286/.pyenv/versions/3.8.7/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "autolock-bug.py", line 28, in code_failing
    await renewer.close()
  File "/Users/aca286/.local/lib/python3.8/site-packages/azure/servicebus/aio/_async_auto_lock_renewer.py", line 236, in close
    await asyncio.wait(self._futures)
  File "/Users/aca286/.pyenv/versions/3.8.7/lib/python3.8/asyncio/tasks.py", line 413, in wait
    raise ValueError('Set of coroutines/Futures is empty.')
ValueError: Set of coroutines/Futures is empty.

Metadata

Metadata

Labels

ClientThis issue points to a problem in the data-plane of the library.MessagingMessaging crewService BusbugThis issue requires a change to an existing behavior in the product in order to be resolved.customer-reportedIssues that are reported by GitHub users external to the Azure organization.issue-addressedWorkflow: The Azure SDK team believes it to be addressed and ready to close.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions