Skip to content

Potential memory leak: CIMultiDict objects never garbage collected #159

@hoenie-ams

Description

@hoenie-ams

Please confirm the following

  • I understand this is open source software provided for free and that I might not receive a timely response.
  • I am positive I am NOT reporting a (potential) security
    vulnerability, to the best of my knowledge. (These must be shared by
    submitting this report form instead, if
    any hesitation exists.)
  • I am willing to submit a pull request with reporoducers as xfailing test cases or even entire fix. (Assign this issue to me.)

Describe the bug

First of all, thanks for all your amazing work on open source!

Hopefully, I am at the right place for this issue, but it might belong in another package (like multidict, aiohttp, scrapy or scrapy-zyte-api). The issue I encountered happened exactly when 0.4.0 got released though.

So after upgrading from propcache 0.3.2 to 0.4.0, CIMultiDict objects
from aiohttp HTTP headers accumulate in memory and are never released.
gc.collect() has no effect, indicating strong references are being held.

I suspect that changes in src/propcache/_helpers_c.pyx may be caching
properties that reference these objects without proper cleanup.

To Reproduce

Sorry I don't have a copy/past example, it is part of a scrapy project that I cannot share unfortunately. But here are some details:

  • Run long-running aiohttp client (via scrapy-zyte-api in my case)
  • Process thousands of HTTP requests
  • Monitor: sum(1 for obj in gc.get_objects() if type(obj).__name__ == 'CIMultiDict')
  • Count grows linearly with requests and never decreases

Packages used:

  • propcache: 0.4.0
  • aiohttp: 3.13.0
  • multidict: 6.7.0

Expected behavior

Expected: CIMultiDict objects should be garbage collected after use
Actual: They accumulate indefinitely (~1 per request)

Logs/tracebacks

N.A.

Python Version

3.13

propcache Version

0.4.0

OS

Linux

Additional context

Workaround: Pin to propcache==0.3.2, multidict==6.6.3 & aiohttp==3.12.14 solved it

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions