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.

Memory leak using python3.8 and boto3 client

See original GitHub issue

Describe the bug We upgraded from python2.7 to python3.8, we are using boto3-1.18.31.dist-info, botocore-1.23.20.dist-info uname -a output is: Linux 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux.

Steps to reproduce Below is the snippet we are using:

import boto3

def poll_queue(client, qurl):
        messages = client.receive_message(QueueUrl=qurl, MaxNumberOfMessages=1, WaitTimeSeconds=0)
        if 'ResponseMetadata' in messages:
                response_meta = messages['ResponseMetadata']
        else:
                return False


def main():
        sqs = boto3.resource('sqs', region_name='us-west-2')
        client = boto3.client('sqs', region_name='us-west-2')
        onboard_tmp = (sqs.get_queue_by_name(QueueName='test1_q.fifo')).url
        orch_tmp = (sqs.get_queue_by_name(QueueName='test2_q.fifo')).url
        inst_tmp = (sqs.get_queue_by_name(QueueName='test3_q.fifo')).url

        while True:
                poll_queue(client, onboard_tmp)
                poll_queue(client, orch_tmp)
                poll_queue(client, inst_tmp)
main()

On examining the process memory usage, it continuously leaks, we are doing the following command to check(Note that the leak is slow and ultimately linux kernel oom kills the process.)

while true; do ps -o pid,user,%mem,command ax | sort -b -k3 -r | grep <pid> ;date ; sleep 5; done
>>>  51384 root      5.1 python3 sqs_leak_test.py

The current memory usage as shown above is 5.1, this started from 0.1 and over the course of few hours it reached 5.1, ultimately it would go to 100.

Expected behavior Confirmed with python2.7 on the same host that issue does not happen, the “receive_message” is the culprit here.

Debug logs Let me know if more info is needed.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
saturntcommented, Dec 9, 2021

Let me ask our devops team, will get back. I created a new instance with ubuntu and it does not seem to leak with the same program. Will try with different variations now. Let me get back.

0reactions
tim-finnigancommented, Jul 7, 2022

Since we haven’t heard back for a few months I’m going to close this. If you’re still experiencing the issue please let us know. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Diagnosing Memory leak in boto3 - python - Stack Overflow
If you suspect a memory leak, the way to identify it is to create a memory dump at some point when memory usage...
Read more >
Best practices boto3 with flask (memory leak) : r/aws - Reddit
I have a simple flask api which downloads and uploads files to s3. This is hosted on an Apache server on an EC2....
Read more >
Memory Leak in Python requests - GeeksforGeeks
When a programmer forgets to clear a memory allocated in heap memory, the memory leak occurs. It's a type of resource leak or...
Read more >
How to Combat Python Memory Leaks | Scout APM Blog
A Python memory leak is a situation where the available memory space is reduced due to improper memory management and failure to release...
Read more >
Error handling — Boto3 Docs 1.26.32 documentation - AWS
This is a general exception when an error response is provided by an AWS service to your Boto3 client's request. Additional client-side issues...
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