Skip to content

Client _subscriptions are not removed when their job terminates and leak per long-lived session #56

@nficano

Description

@nficano

ARCPClient._subscriptions is populated at src/arcp/_client/ops.py:164 for every successful client.subscribe(job_id) and removed only by client.unsubscribe(job_id) at src/arcp/_client/ops.py:180. When the upstream job terminates, _on_job_terminal in src/arcp/_client/dispatch.py:117 pops the entry from _handles and resolves the terminal future, but the matching _subscriptions[job_id] entry is never removed; _fail_all_handles at src/arcp/_client/client.py:177 clears _handles but not _subscriptions. The leftover JobSubscription keeps a reference to the now-terminal JobHandle, so a long-lived client that subscribes to many short jobs accumulates entries (and their associated handles, which hold bytes of past chunks and event histories pinned by closed queues) until client.close(). Users following the examples/subscribe/client.py pattern have no signal that they should call unsubscribe; the docstring at src/arcp/_client/handles.py:117 does not mention manual cleanup.

Fix prompt: When a job's terminal envelope arrives, treat the subscription as ended. In _on_job_terminal at src/arcp/_client/dispatch.py:114, pop the entry from client._subscriptions alongside client._handles. Update _fail_all_handles at src/arcp/_client/client.py:177 to also clear _subscriptions. Document the lifecycle in the JobSubscription and JobHandle docstrings: terminal events end the subscription automatically; clients only need to call unsubscribe() to opt out before completion. Add a regression test that subscribes to a job, runs it to completion, asserts client._subscriptions is empty, and asserts no JobSubscription is referenced from gc.get_referrers(handle) after the terminal event.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingseverity:lowLow severity

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions