#31515: Django tries to reuse MySQL connections that have gone away with ASGI.
---------------------------------+------------------------------------
Reporter: Braunson | Owner: nobody
Type: Bug | Status: new
Component: Documentation | Version: 3.0
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Comment (by Carlton Gibson):
OK, I can't yet pin the exact difference between stable/3.0.x and master,
but the issue looks at least partly to do with uvicorn.
I see a stable 20 connections opened. This ties in with what we saw on
#31134:
>I finally understood DB connection lifecycle and uvicorn workers. First
of all uvicorn for every worker starts 10 threads so for 2 workers there
will be 20 opened connections, for 10 workers it will be 100 connections.
>
>Django requires to have non-transactional requests to close the
connection after CONN_MAX_AGE and because when I set ATOMIC_REQUESTS to
True, Django will always leave the open connection but firstly when the
connection was open longer than CONN_MAX_AGE, Django will reestablish that
connection once again.
>[https://code.djangoproject.com/ticket/31134#comment:7 comment:7]
Running in WSGI mode, uvicorn still opens multiple DB connections, 10 it
seems — need to look at the number of workers there.
{{{
$ uvicorn --interface wsgi djangobug_repro.wsgi:application
}}}
VS the same thing with gunicorn, where we just have the single connection.
{{{
$ gunicorn djangobug_repro.wsgi:application
}}}
So **even** with WSGI uvicorn is behaving differently.
The reporter on #31134 concluded this was uvicorn's expected behaviour.
(I'd need to look at uvicorn's source code to determine that for myself.)
We need to investigate further the difference with master. We're calling
`response.close()` inside `sync_to_async` there. Adding that to
stable/3.0.x doesn't resolve this issue. We're looking at if, on master,
we need to use `tread_sensitive` there.
--
Ticket URL: <https://code.djangoproject.com/ticket/31515#comment:26>
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/067.fc2bcf6735f99415b14097f13c96ad1a%40djangoproject.com.