msgpack / msgpack-python

MessagePack serializer implementation for Python msgpack.org[Python]
https://msgpack.org/
Other
1.91k stars 229 forks source link

memory leak observed in python 3.12.1 #579

Closed TheRealMcoy closed 7 months ago

TheRealMcoy commented 8 months ago

This library appears to leak memory in Unpacker method under Python 3.12.1

reproducer script:

import msgpack
from io import BytesIO

while True:

   buf = BytesIO()
   for i in range(100):
      buf.write(msgpack.packb(i, use_bin_type=True))

   buf.seek(0)

   unpacker = msgpack.Unpacker(buf, raw=False)
   for unpacked in unpacker:
       print(unpacked)

Python 3.11.7 after 10 minute run: python3 11

Python 3.12.1 after 10 minute run: python3 12

senyai commented 7 months ago

I have similar situation, but my test case is a bit different:

from msgpack import Unpacker, packb

unpacker = Unpacker()
network_packet = packb(None)

for i in range(2000000):
    unpacker.feed(network_packet)
    for unpacked in unpacker:
        pass
methane commented 7 months ago

@TheRealMcoy @senyai do you use macOS?

methane commented 7 months ago

Sorry, OS is not related.

https://github.com/cython/cython/issues/5724 caused it. Until I make mew release, manually run Cython locally will fix it.

senyai commented 7 months ago

@methane recompiling with new cython fixed it for me, much appreciated.

TheRealMcoy commented 7 months ago

@methane the latest 1.0.8 has resolved the memory leak, many thanks!