Database connections being left open
See original GitHub issuePython: 3.6.5 Django: 2.1.2 sentry-sdk: 0.4.2
I upgraded from raven to sentry-sdk yesterday and noticed my app was now keeping database connections open rather than closing them per request.
I wrote a tiny view to test this:
def sentry_test(request):
from django.contrib.auth.models import User
print(User.objects.all())
return HttpResponse("<h1>Hello</h1>")
and when GET the URL repeatedly I see the subsequent connections remain idle after the request has completed:
=> SELECT state, query FROM pg_stat_activity WHERE client_addr IS NOT NULL;
state | query
--------+-----------------------------------------------------
idle | SELECT "auth_user"."id", "auth_user"."password", ...
active | SELECT state, query FROM pg_stat_activity WHERE client_addr IS NOT NULL;
idle | SELECT "auth_user"."id", "auth_user"."password", ...
idle | SELECT "django_migrations"."app", "django_migrations"."name" FROM "django_migrations"
idle | SELECT "auth_user"."id", "auth_user"."password", ...
idle | SELECT "auth_user"."id", "auth_user"."password", ...
idle | SELECT "auth_user"."id", "auth_user"."password", ...
As you can see the connection from the migrate query on startup has remained open too.
If I use raven this behaviour is not exhibited.
I suspect this won’t help much, but if I use sentry-sdk and comment out:
WSGIHandler.__call__ = sentry_patched_wsgi_handler
Then the problem doesn’t manifest itself but I’ve basically turned off sentry at this stage.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Common Reasons Why Connections Stay Open for a Long ...
Body. When you are monitoring connection pool performance, you may occasionally notice that connections are staying open for long periods of time.
Read more >is it safe to keep database connections open for long time
Absolutely it is safe to do this. This is how client-server applications work. If you are using a three-tier application, the application ...
Read more >Does leaving a connection open for a matter of seconds cause ...
I can only speak toward SQL Server. A database connection itself is not going to cause deadlocks. If it did connection pooling would...
Read more >What If I leave Sql Connection Opened ? - MSDN
Connections hold open valuable resources to the database, consume memory, and can lock data that could cause other queries to slow down. So...
Read more >Running Out of Database Connections - 3ap Engineering Blog
Your connection pool is running out of database connections. ... This points to the Transaction still being open during renderDocument .
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the separate investigation 😃 will release asap
Tested and verified connections are being closed correctly.