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.

Potential memory leak in MultipartWriter._upload_next_part

See original GitHub issue

MultipartWriter._upload_next_part Memory leak

the MultipartWriter._upload_next_part function upload the bytesIo from Memory to s3(by upload[CreateMultipartUpload]),but do not clean bytesIO (in Memory). i use the smart_open.open() (gz file) upload to s3,the Memory Keep increasing。 I check the code and focus the MultipartWriter._upload_next_part() :

        self._buf.seek(0)
        part = self._mp.Part(part_num)
        upload = _retry_if_failed(functools.partial(part.upload, Body=self._buf))
        self._parts.append({'ETag': upload['ETag'], 'PartNumber': part_num})
        logger.debug("upload of part #%i finished" % part_num)

        self._total_parts += 1
        self._buf = io.BytesIO()

after upload the bytesIO, not clean the Memory.

bug fix code

        self._buf.seek(0)
        part = self._mp.Part(part_num)
        upload = _retry_if_failed(functools.partial(part.upload, Body=self._buf))
        self._parts.append({'ETag': upload['ETag'], 'PartNumber': part_num})
        logger.debug("upload of part #%i finished" % part_num)

       
        self._buf.truncate()# clean the Memory , avoid Memory leak
        self._total_parts += 1
        self._buf = io.BytesIO()

Versions

python 3.7 smart_open 2.0.0

Checklist

https://docs.python.org/zh-cn/3/library/io.html

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
SchopenhauerZhangcommented, Jun 16, 2020

wouldn’t the garbage collector take care of this? em, i use smart_open in High concurrency and high throughput distributed system. wait the garbage collector(python’s) to deal it is not good idea. I suppose to recycle the memory by self. I will try to recycle the memory by self, later i write the result at here. Thanks!

0reactions
mpenkovcommented, Oct 10, 2021

@cnmoise Can you reproduce the problem with the newest version of smart_open? We’ve reworked the buffering in the S3 submodule significantly, and it’s likely the problem is no longer there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Potential memory leak? - c++ - Stack Overflow
It seems to me that, later, we cannot releasing all the spaces that is allocated to original char *str. Is this right?
Read more >
Configuring the memory leak policy - IBM
You can configure a leak detection, prevention, and action policy to accommodate your applications and environment so that potential memory leaks are ...
Read more >
Understanding Memory Leaks in Java - Baeldung
Memory leaks are a genuine problem in Java. In this tutorial, we'll learn what the potential causes of memory leaks are, how to...
Read more >
Tutorial: Find a memory leak | IntelliJ IDEA Documentation
Memory leak is visible on CPU and Memory Live Charts ... That's ten base images that correspond to the possible positions of the...
Read more >
How to Detect Memory Leaks in Java: Causes, Types, & Tools
Excessive usage of static fields can potentially lead to a memory leak. In Java, static fields usually remain in memory as long as...
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