Skip to content

Memory leak on connection close due to circular referenceΒ #746

Open
@francis-clairicia

Description

@francis-clairicia

❓ I'm submitting a ...

  • 🐞 bug report
  • 🐣 feature request
  • ❓ question about the decisions made in the repository

🐞 Describe the bug. What is the current behavior?

In an environment where the automatic garbage collection is disabled by default and gc.collect(2) is called manually (in this case, once every 10 minutes), there has been a considerable increase in the size of the garbage collector.
After analysis, this is the cause:

cheroot/cheroot/server.py

Lines 1264 to 1271 in 1391e71

# LRU cached methods:
# Ref: https://stackoverflow.com/a/14946506/595220
self.resolve_peer_creds = (
lru_cache(maxsize=1)(self.resolve_peer_creds)
)
self.get_peer_creds = (
lru_cache(maxsize=1)(self.get_peer_creds)
)

Reassigning a method to an object creates a circular reference.

❓ What is the motivation / use case for changing the behavior?

This feature seems to be here for caching UNIX sockets credentials. But we use cheroot only for internet connection so this cache system is useless. And even for a UNIX server, this piece of code creates some problems.

πŸ’‘ To Reproduce

Steps to reproduce the behavior:

  1. Run a server with automatic garbage collection disabled and log number of objects in garbage ( using len(gc.get_objects()) ) at regular interval.
  2. Have a script which makes a lot of temporary connections ( without Keep-Alive ).
  3. We can see the increase in the number of items tracked by the garbage collector.

πŸ’‘ Expected behavior

No memory leak.

πŸ“‹ Details

πŸ“‹ Environment

  • Cheroot version: 10.0.1
  • CherryPy version: None
  • Python version: 3.11.11
  • OS: Linux
  • Browser: all

πŸ“‹ Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is brokenreproducer: missingThis PR or issue lacks code, which reproduce the problem described or clearly understandable STR

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions