Skip to content

Conversation

@freewil
Copy link

@freewil freewil commented Dec 18, 2025

  • get_info(): Cache only the exception message
  • Create fresh exceptions
  • No traceback accumulation, no memory leak, cleaner code

Caching the exception objects for address and fingerprint get_info() params and re-raising them creates an accumulation of python frame and traceback objects, essentially creating a memory leak with observable linear growth of memory usage over time.

This appears to be an anti-pattern and prevents the python garbage collector from collecting these exceptions and also creates references to other objects, preventing collection.

Instead of caching the entire exception object,
this commit just caches the exception string,
ensuring no unintentional references are created
that accumulate frame, tracebacks, or other application objects.

see torproject/nyx#52

* get_info(): Cache only the exception message
* Create fresh exceptions
* No traceback accumulation, no memory leak, cleaner code

Caching the exception objects for `address` and `fingerprint`
get_info() params and re-raising them creates an accumulation
of python frame and traceback objects, essentially creating a
memory leak with observable linear growth of memory usage over time.

This appears to be an anti-pattern and prevents the python garbage
collector from collecting these exceptions and also creates
references to other objects, preventing collection.

Instead of caching the entire exception object,
this commit just caches the exception string,
ensuring no unintentional references are created
that accumulate frame, tracebacks, or other application
objects.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant