-
Notifications
You must be signed in to change notification settings - Fork 42
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
Database connections are never closed #340
Comments
I could prepare a PR dropping the singleton caching and moving all caching logic to the psycopg_pool (as it should imo). |
PgstacDB is set up with a disconnect method that is called both when using as a context manager (via the exit() method) as well as by trapping it using atexit.register(self.disconnect) to ensure that connections are automatically returned to the pool. |
I'm confused about the purpose of using ConnectionPool and having the db_max_idle setting if they're not meant to be used. If users are expected to initialize PgstacDB via a context manager each time, creating a new pool just to get a single connection and then closing everything afterward, what's the benefit? The typical use case in SQLAlchemy/Redis/Valkey is to maintain the same connection pool throughout the program's lifecycle - that's where settings like db_max_idle make practical sense. What you describe would also result in a constant memory leak due to repeated All of these seem like unusual design decisions that cause more issues than they solve. I thought PostgreSQL connection pooling was a solved problem. |
I've been reviewing the pgstac/src/pypgstac/src/pypgstac/db.py Line 168 in d5901b7
None pgstac/src/pypgstac/src/pypgstac/db.py Line 173 in d5901b7
As a result, the pool is never reused across different context managers:
|
PgstacDB maintains a persistent connection to the database through
self.connection = pool.getconn()
. According to thegetconn()
documentation, this connection will not be automatically returned to the pool, and therefore won't be closed when idle. An explicitputconn()
call is required. Currently,db_max_idle
is ignored, which leads to database timeouts during long idle periods. I suggest not implementing a customself.connection
singleton pooling logic, but rather relying on thepsycopg_pool
implementation. Otherwise, you would need to implement the same feature set aspsycopg_pool
, including idle handling, which adds unnecessary complexity.The text was updated successfully, but these errors were encountered: