question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possible memory leak receiving messages in servicebus 0.50.3

See original GitHub issue
  • Package Name: servicebus
  • Package Version: 0.50.3
  • Operating System: Linux Alpine/Debian, OSX
  • Python Version: 3.8.6

Describe the bug Apparently memory leaks from receiving messages.

To Reproduce Steps to reproduce the behavior:

  1. create a queue client
  2. create a receiver
  3. receive (and ignore) a message
  4. back to point 1

Expected behavior No relevant memory usage increase.

Code

Here a sample of the code I use to replicate. Notice I am not processing messages and I am running against an empty queue.

import os

from azure.servicebus import ServiceBusClient, ReceiveSettleMode


if __name__ == '__main__':

    service_bus_client = ServiceBusClient(service_namespace=os.environ['AZURE_BUS_NAMESPACE'],
                                          shared_access_key_name=os.environ['AZURE_BUS_KEY_NAME'],
                                          shared_access_key_value=os.environ['AZURE_BUS_KEY_VALUE'])
    queue_name = '-'.join([os.environ['AZURE_BUS_QUEUE'], 'low'])

    for _ in range (1000000):
        # ofc I could create the queue once, but this is closer to my actual code
        queue = service_bus_client.get_queue(queue_name=queue_name)
        with queue.get_receiver(mode=ReceiveSettleMode.PeekLock) as receiver:
            msg_batch = receiver.fetch_next(max_batch_size=1, timeout=1)
            # notice I do not really expect to receive any message, printing just to keep it busy....
            print(msg_batch)

Additional context I know that I am not running on the latest version, but I have the feeling the issue might be in the uamqp layer and therefore of interest for also the new versions as well.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:22 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
yunhaolingcommented, Jul 13, 2021

apologize for missing the thread here @alberto-delgado-maersk, and thanks @miroag for bringing it to my attention! I’ll investigate into the issue this week.

2reactions
alberto-delgado-maerskcommented, Jun 4, 2021

Hi @yunhaoling, it seems there are still some memory issues in version 7.2.0 of the service bus python package.
I ran a similar version to the script below for around 6 hours, explicitly calling the GC every few iterations and the memory just kept growing.

        while passed_secs < time_limit_secs:
            # ofc I could create the queue once, but this is closer to my actual code
            with service_bus_client.get_queue_receiver(queue_name=queue_name) as receiver:
                msg_batch = receiver.receive_messages(max_message_count=1,
                                                    max_wait_time=3)
                # notice I do not really expect to receive any message, printing just to keep it busy....
                print(msg_batch)
                if cnt % 100 == 0:
                    print("Forcing GC to run")
                    gc.collect()

Below you can see also a plot of how the memory grows: single_service_bus

When instead I initialized the service bus client within the while loop above, we see that the memory increases at a much slower rate: restart_service_bus

Could you check if you see the same at your end?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Memory leak in the Azure Service Bus Queue - MSDN
Every time this code is executed memory leaks approximately 1Mb. I tried to put "BrokeredMessage" inside "using" statement but that did not help ......
Read more >
azure-servicebus - PyPI
Send and receive messages within your Service Bus channels. Utilize message locks, sessions, and dead letter functionality to implement complex messaging ...
Read more >
Azure Message Bus not releasing memory - Stack Overflow
The memory that is used maybe waiting for garbage collection t run. Garbage collection is not predictable when it will run. It is...
Read more >
Releases - ImmyDocs
Added a warning message whenever the Ephemeral Agent's Ping RPC method takes ... job causing memory to bloat; You can now get registration...
Read more >
Index of /pub/fedora/linux/releases/35/Everything/x86_64/os ...
perl-Devel-Leak-0.03-47.fc35.x86_64.rpm 2021-07-27 04:33 18K [ ] ... perl-Email-Received-1.00-25.fc35.noarch.rpm 2021-07-27 04:34 18K [ ] ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found