Skip to content

Free-threaded builds: an idle worker thread keeps a sync route handler's last response #873

Backlog

Description

@JuroOravec

(Opus 5.5)

On a free-threaded build with the GIL off, an object created on one thread and dropped by another is freed only when the thread that created it next runs Python code. #870 handled this for Citry's own Events check threads by having an idle check thread wake once a second.

Route handlers that are plain functions have the same pattern. The ASGI adapter runs them through asyncio.to_thread (packages/py/citry/citry/util/routing.py, the function that calls route handlers), which uses the event loop's default thread pool. A handler builds its response, and often request data and rendered HTML, on a pool thread. The caller drops them, but if that pool thread then sits idle, waiting for the next job with no time limit, those objects stay in memory until the thread gets more work.

This is a delay, not a leak: a busy server keeps its pool threads running. A quiet server, or one with a large pool, can hold the last responses of each idle thread for a long time.

Possible fixes, to compare:

Found during the review of #870. Related: #848. Suggested for 1.4.0.

🤖 Generated with Claude Code

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions