Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Pool dangling connections #109

Merged
merged 28 commits into from
Aug 26, 2024

Conversation

stankudrow
Copy link
Contributor

@stankudrow stankudrow commented Aug 20, 2024

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 stankudrow marked this pull request as draft August 20, 2024 22:15
@stankudrow stankudrow marked this pull request as ready for review August 21, 2024 15:33
@stankudrow
Copy link
Contributor Author

@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
Copy link
Contributor Author

@DFilyushin , many thanks for approval.

@stankudrow
Copy link
Contributor Author

stankudrow commented Aug 22, 2024

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

@gnomeby
Copy link
Contributor

gnomeby commented Aug 22, 2024

OK. will see.

@stankudrow
Copy link
Contributor Author

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

Copy link
Contributor

@DaniilAnichin DaniilAnichin left a comment

Choose a reason for hiding this comment

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

I'm not that big in terms of maintaining, usually I just request to fix bugs or something like that.
I've looked through this one, found no issues except a minor comment on debug logs

asynch/proto/connection.py Outdated Show resolved Hide resolved
@stankudrow
Copy link
Contributor Author

stankudrow commented Aug 25, 2024

@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.

@long2ice
Copy link
Owner

Thanks!

@long2ice long2ice merged commit 74904ef into long2ice:dev Aug 26, 2024
1 check passed
@gnomeby
Copy link
Contributor

gnomeby commented Aug 26, 2024

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
`

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.

5 participants