-
Notifications
You must be signed in to change notification settings - Fork 79
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
Doesn't close DB connections leading to "FATAL: sorry, too many clients already" #86
Comments
@Volpym did you end up figuring out what was causing this? I'm running into the same thing. |
@agamrp unfortunately no. |
@agamrp Due to lack of time, I had to use another module (not sure if I'm allowed to share its name but with a google search you will find it). |
In case someone still have this problem. Try to use the latest version. These two lines should fix it. |
also mentioned: #76 ? |
Hi, I am in the same situation, even though I enabled the new middleware. In the run arguments, there are For each thread, Django will create a connection, because the connections are not shared across threads. See the following code taken from recent Django version ( class BaseConnectionHandler:
settings_name = None
exception_class = ConnectionDoesNotExist
thread_critical = False
def __init__(self, settings=None):
self._settings = settings
self._connections = Local(self.thread_critical)
# ...
def __getitem__(self, alias):
try:
return getattr(self._connections, alias)
except AttributeError:
if alias not in self.settings:
raise self.exception_class(f"The connection '{alias}' doesn't exist.")
conn = self.create_connection(alias)
setattr(self._connections, alias, conn)
return conn
# ... In my case, it was 256 connections at most (16 times 16). But in PostgresQL the max connection number is 100. This could lead to such errors with high concurrency. Regarding that the connections in each thread are considered as "active", I suggest having a fair number of processes and as well as number of threads in our own applications. Correct me if I misunderstood anything 🙏 |
Thank you very much for the investigation @Inokinoki ! 🙏 It would be interesting to hear if this solves the issue for the others. |
Thanks for your investigation @Inokinoki django-db-connection-pool uses sqlalchemy pooling under the hood and share connection between threads inside each process, so 500+ gevent workers can reuse the same connections. |
Thanks for the feedback and the connection pool lib! Indeed I was also considering doing that |
Hi!
I have 5 tasks that run periodically (using periodiq) and each time they these are executed they open a new connection to the database.
Already tried the middleware ordering showcased on issue #76.
Thank you in advance
The text was updated successfully, but these errors were encountered: