asynch icon indicating copy to clipboard operation
asynch copied to clipboard

Fix `Pool` dangling connections

Open stankudrow opened this issue 1 year ago • 4 comments

The MRs #106 and #107 were only foresteps to the real problem: poor connection management via the Pool class. My colleagues found that the version 0.2.4 leaves unclosed/dangling connections to the ClickHouse. Rolling back to the previous v0.2.3 made this problem disappear. Moreover, there is the discussion #108 highlighting the same problem.

This PR #109 addresses the dangling connection issue by injecting into the Pool class the interface for asynchronous context manager support. When entering a pool context, the minsize connections are established. Within the pool context one can acquire up to the maxsize connections, but not more or PoolError will be raised. Before leaving the pool context, all connections get closed.

Many thanks to the psycopg_pool open-source implementation and this article on psycopg3 pool design.

UPD

Sorry for overloading the PR with changes on Connection class, including tests on asynch.proto.Connection class and some minor grooming or refactoring. That is the result of API alignment in my opinion + bringing more order and unification in the API.

stankudrow avatar Aug 20 '24 21:08 stankudrow

@long2ice , I need thorough reviews on this PR, it is about changes in architecture, could you ping/tag other maintainers?

@DFilyushin, please review this PR as well (also keeping on the discussion #108 ).

stankudrow avatar Aug 21 '24 15:08 stankudrow

@DFilyushin , many thanks for approval.

stankudrow avatar Aug 22 '24 11:08 stankudrow

@boolka , @gnomeby , @DaniilAnichin , @pufit , @KPull , @lxneng , could you possibly share your thoughts, leave your comments and review this PR as well?

stankudrow avatar Aug 22 '24 15:08 stankudrow

OK. will see.

gnomeby avatar Aug 22 '24 16:08 gnomeby

@gnomeby , @long2ice , could you have a thorough look at this work?

stankudrow avatar Aug 25 '24 16:08 stankudrow

@boolka , could you review this PR with the approve of yours when an agreement with (maybe almost) all items on this work will be attained?

@gnomeby , the same request for a review, s'il vous plaît.

stankudrow avatar Aug 25 '24 20:08 stankudrow

Thanks!

long2ice avatar Aug 26 '24 02:08 long2ice

Not working for me: ` 2024-08-26 12:16:04 asynch.proto.connection WARNING | Connection was closed, reconnecting.

2024-08-26 12:16:35 asynch.pool WARNING | Connection lost `

gnomeby avatar Aug 26 '24 10:08 gnomeby