Skip to content

Commit 3ffe64a

Browse files
Clarify ClusterClient ownership contract
Expand ConnectionPool.__init__ docstring to state who closes the cluster, whether sharing across pools is safe, and what pool.close() actually does. Previous docstring said only "Externally-owned ClusterClient" which left three questions unanswered: - Does pool.close() close the cluster? Answer: no. - May one cluster back many pools? Answer: yes. - Is out-of-pool use of the cluster safe? Answer: yes, each leader-query opens a short-lived socket that does not contend with pool checkout. Also clarifies that when the pool constructs its own cluster (from node_store= or addresses=), pool.close() still does not close it — leader-query sockets are short-lived, and the NodeStore is caller-owned. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 3cd8900 commit 3ffe64a

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

src/dqliteclient/pool.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,24 @@ def __init__(
7575
cluster: Externally-owned ClusterClient. Lets multiple pools
7676
share one ClusterClient (and thus its node store, leader
7777
cache, etc.) across databases or tenants.
78+
79+
Ownership: the pool does NOT take ownership of this
80+
cluster. The caller is responsible for eventually calling
81+
``cluster.close()`` and MUST NOT close the cluster while
82+
any pool is still in use. ``pool.close()`` does not close
83+
the cluster — it only drains pool-owned connections.
84+
85+
Sharing: one ClusterClient may back multiple pools
86+
concurrently. Direct use of the cluster (e.g.,
87+
``await cluster.find_leader()``) from outside the pool is
88+
safe — each call opens a short-lived leader-query socket
89+
and does not contend with pool checkout.
7890
node_store: Externally-owned NodeStore used to build a new
79-
ClusterClient. Mutually exclusive with ``cluster``.
91+
ClusterClient. Mutually exclusive with ``cluster``. Note
92+
that ``pool.close()`` does not close this auto-constructed
93+
cluster either — leader-query sockets it opens are
94+
short-lived and close on their own; the NodeStore itself
95+
is caller-owned.
8096
max_total_rows: Cumulative row cap across continuation
8197
frames for a single query. Forwarded to every
8298
:class:`DqliteConnection` the pool hands out, so every

0 commit comments

Comments
 (0)