Skip to content

Fix memory leak from retained exception tracebacks#168

Merged
woolimcho merged 1 commit into
quora:masterfrom
woolimcho:fix/traceback-memory-leak
Apr 8, 2026
Merged

Fix memory leak from retained exception tracebacks#168
woolimcho merged 1 commit into
quora:masterfrom
woolimcho:fix/traceback-memory-leak

Conversation

@woolimcho

@woolimcho woolimcho commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

When an async task fails, error._traceback and self._frame hold live references to frame objects and their locals:

AsyncTask._error → ._traceback → traceback → frame → f_locals
AsyncTask._frame → frame → f_locals, f_globals

GC cannot collect these because they are reachable from the live AsyncTask (held by callers or creator chains), not unreachable cycles.

Fix: clear self._frame in _computed() after the task finishes, and clear error._traceback after generator.throw() propagates it. Also migrate to single-arg throw(error) (3-arg form is deprecated).

When an async task fails, error._traceback and self._frame hold live
references to frame objects and their locals:

    AsyncTask._error → ._traceback → traceback → frame → f_locals
    AsyncTask._frame → frame → f_locals, f_globals

GC cannot collect these because they are reachable from the live
AsyncTask (held by callers or creator chains), not unreachable cycles.

Fix: clear self._frame in _computed() after the task finishes, and
clear error._traceback after generator.throw() propagates it. Also
migrate to single-arg throw(error) (3-arg form is deprecated).

@ilevkivskyi-quora ilevkivskyi-quora left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, LG!

@woolimcho woolimcho merged commit 2983cde into quora:master Apr 8, 2026
10 checks passed
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.

2 participants