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
Enforce for max_lifetime
in pool.check()
#482
Labels
Comments
dvarrazzo
changed the title
Enforce for
Enforce for Jan 11, 2023
max_lifetime
in poo.check()
max_lifetime
in pool.check()
It should be as easy as (untested): diff --git a/psycopg_pool/psycopg_pool/pool.py b/psycopg_pool/psycopg_pool/pool.py
index 609d95df..47c9561b 100644
--- a/psycopg_pool/psycopg_pool/pool.py
+++ b/psycopg_pool/psycopg_pool/pool.py
@@ -409,6 +409,13 @@ class ConnectionPool(BasePool[Connection[Any]]):
while conns:
conn = conns.pop()
+
+ if conn._expire_at <= monotonic():
+ logger.info("discarding expired connection %s", conn)
+ conn.close()
+ self.run_task(AddConnection(self))
+ continue
+
try:
conn.execute("SELECT 1")
if conn.pgconn.transaction_status == TransactionStatus.INTRANS: It needs the equivalent async, tests in the test suite, an entry in the changelog. It seems simple enough if someone would like to try it. |
dvarrazzo
added
good first issue
Good for newcomers
pool
The issue is related to the psycopg_pool package
labels
Jan 11, 2023
dvarrazzo
added a commit
that referenced
this issue
Jun 8, 2023
dvarrazzo
added a commit
that referenced
this issue
Jun 8, 2023
dvarrazzo
added a commit
that referenced
this issue
Jun 13, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
I'm also thinking that
check()
might be a good moment to check ifmax_lifetime
is expired, because it's already in the business of taking out all the connections from the pool and exercise them. This is much simpler and can be done in a bugfix for psycopg_pool 3.1. It would be up to the user to callpool.check()
periodically.Originally posted by @dvarrazzo in #247 (comment)
The text was updated successfully, but these errors were encountered: