You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Idle PostgreSQL connections leak, leading to connection exhaustion #1632
Describe the bug
TubeSync continuously opens and accumulates persistent idle database connections in PostgreSQL over time. Even when frontend worker configurations (like Gunicorn workers) are restricted, background tasks or worker threads appear to spawn and orphan database sockets without properly closing or recycling them. Eventually, this exhausts PostgreSQL's max_connections limit, resulting in connection refusal errors across services sharing the same database cluster: 53300: remaining connection slots are reserved for roles with the SUPERUSER attribute
To Reproduce
Steps to reproduce the behavior:
Deploy TubeSync using PostgreSQL as the backend database.
Let the container run normal background feed polling and synchronization tasks over a few minutes.
Check active database connections on the PostgreSQL server (e.g., via pg_stat_activity).
Observe a growing, un-reaped accumulation of tubesync connections sitting in an idle state.
Expected behavior
TubeSync workers should properly check out, utilize, and return/close database connections to the pool when tasks complete, maintaining a stable and conservative connection footprint without leaking sockets.
Logs / Screenshots
PostgreSQL process list snippet showing the accumulation of idle connections:
I haven't actually seen any evidence of leaked connections.
There are quite a few processes now and each is going to maintain its own pool.
This can be adjusted in common/utils.py around line 191.
You can change min_size to zero so that no idle connections are maintained, but I would not recommend that.
tubesync=# ALTER SYSTEM SET idle_session_timeout = "1h";
ALTER SYSTEM
tubesync=# SELECT pg_reload_conf();
pg_reload_conf
----------------
t
(1 row)
tubesync=# SHOW idle_session_timeout;
idle_session_timeout
----------------------
1h
(1 row)
tubesync=#
I've tracked down a fork / thread interaction that leaves the child process (the task execution worker) with a pool that has no threads to service the connections.
I'll try to get changes tested and merged into main before the next release.
changed the title [-][Bug] TubeSync leaks idle PostgreSQL connections, leading to connection exhaustion (53300)[/-][+]Idle PostgreSQL connections leak, leading to connection exhaustion[/+]on Nov 2, 2026
Activity
tcely commentedon Nov 2, 2026
I haven't actually seen any evidence of leaked connections.
There are quite a few processes now and each is going to maintain its own pool.
This can be adjusted in
common/utils.pyaround line 191.You can change
min_sizeto zero so that no idle connections are maintained, but I would not recommend that.tubesync/tubesync/common/utils.py
Lines 188 to 198 in 8feb0cd
Watch idle connections
Related
Mitigation
I've tracked down a fork / thread interaction that leaves the child process (the task execution worker) with a pool that has no threads to service the connections.
I'll try to get changes tested and merged into
mainbefore the next release.[-][Bug] TubeSync leaks idle PostgreSQL connections, leading to connection exhaustion (53300)[/-][+]Idle PostgreSQL connections leak, leading to connection exhaustion[/+]