[pypy-issue] [issue1683] BytesIO leaks like hell

gangesmaster tracker at bugs.pypy.org
Thu Jan 30 09:45:23 CET 2014

New submission from gangesmaster <tomerfiliba at gmail.com>:

Our web server was leaking memory over time (twisted+cyclone). For reference:

It turns out it's all due to the following code in cyclone:

    from io import BytesIO as StringIO
    if content_length < 100000:
        self._contentbuffer = StringIO()
        self._contentbuffer = TemporaryFile()

( https://github.com/fiorix/cyclone/blob/master/cyclone/httpserver.py#L168 )

We noticed that only smaller buffers leaked. We're running with:

    Python 2.7.3 (87aa9de10f9c, Nov 24 2013, 20:57:21)
    [PyPy 2.2.1 with GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on 

Here's a code snippet that recreates the problem:

    from io import BytesIO

    while True:
        s = BytesIO()

This code leaks like hell, reaching 1GB in ~3 seconds and soaring up still.

Just for comparison, cStringIO.StringIO and StringIO.StringIO do not leak. 
None of them leak on CPython too.

messages: 6511
nosy: gangesmaster, pypy-issue
priority: bug
release: 2.2
status: unread
title: BytesIO leaks like hell

PyPy bug tracker <tracker at bugs.pypy.org>

More information about the pypy-issue mailing list