#33497: Database persistent connections do not work with ASGI in 4.0
-------------------------------------+-------------------------------------
Reporter: Stenkar | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: 4.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ASGI, Database, | Triage Stage: Accepted
async |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Andreas Pelme):
We have been using `CONN_MAX_AGE=300` since it was introduced in Django
1.6 and rely in it for not having to reconnect to the database in each
http request. This change really caught us off guard. We upgraded from
django 3.2 to 4.0 and our site went completely down in a matter of seconds
when all database connections was instantly depleted.
Giving each http request its own async context makes a lot of sense and is
a good change in itself IMO. But I would argue that this change is not
backward compatible. `CONN_MAX_AGE` does still "technically" work but it
does clearly not behave as it has been doing for the last 10 years.
Specifying `CONN_MAX_AGE` is recommended in a lot of places, including
Django's own docs:
- https://docs.djangoproject.com/en/4.2/ref/databases/#persistent-
database-connections
- https://devcenter.heroku.com/articles/python-concurrency-and-database-
connections
At the very least, I think this needs to be clearly called out in the
release notes and docs on "Persistent connections". I think we need to
deprecate/remove `CONN_MAX_AGE`. Or is there even a reason to keep it
around?
I am very much in favor of getting basic db connection pooling into
django. We will try to give https://github.com/django/django/pull/16881 a
spin and put it in production and report back. Would love to have
something like that available out of the box in Django! We use Postgres
and would be happy with having such a pool which would replace
CONN_MAX_AGE for our use case.
However, that would only work for postgres. What is the situation with
mysql/oracle? Does mysqlclient come with a pool like psycopg?
--
Ticket URL: <https://code.djangoproject.com/ticket/33497#comment:22>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018a8429d2d9-c6712351-6ad3-4a0c-9b38-7d05ca514ee2-000000%40eu-central-1.amazonses.com.