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
postgres connection does not get closed with socket.io requests #174
Comments
Hi Michael, I've also noticed the same issue. I thought using pgbouncer in transaction mode might have solved the problem, but it does not appear to. I'm keenly awaiting some progress on this issue. Lyndon |
But is there some workaround or is this library just not usable at all because of this bug? I mean i really cannot use it like this, since every 100 page reloads i get a server error and need to restart django or postgres. How could anyone try to use it in production? |
I'm facing this issue too, any workarounds to suggest? Thanks! |
@michael1e23
so this means that really Django does it's best to recycle the connection even with gevent patched threads. At this point is only about enable Django to share the connection between different threads
The final code to run the server should then look like this
This may be working and solve the issue, I'll test this on my end, can you please do the same and confirm? @lgarvey Can you please test this too? @abourget Does it sound crazy or can make some sense? Thanks! |
The trick is marked in run.py and then we can have access to database do whatever we want. Solution tested but performance is not verified. Related link is here: abourget/gevent-socketio#174.
I would like to return to the original request of properly closing DB connections, which I think should ideally happen after/during Now the Now I'm using another workaround and trying to close the DB connection after calling on_* and recv_* methods: from django.db import close_old_connections # Django 1.6
class MyNamespace(BaseNamespace):
...
def exception_handler_decorator(self, fun):
def wrap(*args, **kwargs):
try:
return fun(*args, **kwargs)
finally:
close_old_connections()
return wrap
... And closing DB connections in the view too: def socketio(request):
...
socketio_manage(request.environ, namespaces={'': MyNamespace}, request=request)
try:
return HttpResponse(None)
finally:
close_old_connections() This solution works for me, but it is not a good answer to the original question. |
I struggle to make the solution work in production with gunicorn started by supervisord, I fail to make my gunicorn_conf.py see my django settings. It looks like this at the moment (not working):
I get:
What I also tried was:
Any help greatly appreciated :-/ |
Ok, I could fix the IDLE connections building up with this, thanks to @dn0: from django.db import close_old_connections
|
Hello,
i have the problem that my postgres connections dont get closed. If i set max_connections of my postgres server to 5, then i can reload my page five times successfully. After that postgres complains about to many open connections.
I am using
django gevent socketio with the following versions:
My debugging sessions so far show that i have the following problem:
if i have a normal request, i get the stack trace like this:
and in gevent.pywsgi.WSGIHandler.handle_one_response() there is a call to
which closes open database connections. But when i get a socket.io request, the function gevent.pywsgi.WSGIHandler.handle_one_response() does not get called at all. The stack looks like:
and here the new greenlet stack
So where should the database connection be closed in the socket.io case? The distinction between socket.io calls and regular ones seems to happen in:
my runserver.py looks like this:
I know the information i provided is a little unstructured. I just wanted to post my debugging status so far and hope that someone sees the problem while i am going on to find the bug.
Thanks in advance
Michael
The text was updated successfully, but these errors were encountered: