#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 felixxm):

 After some investigation, I think we should close requests with
 `thread_sensitive=True` (that's an issue on master). Without this we do
 not hit connections in the main thread and `CONN_MAG_AGE=0` is not
 respected, Django reuses the same connection (from the same thread). I
 confirmed this checking `performance_schema.threads.THREAD_OS_ID`.

 With `thread_sensitve=True`, connections are closed after each request as
 expected:

 {{{
 diff --git a/django/core/handlers/asgi.py b/django/core/handlers/asgi.py
 index 82d2e1ab9d..3bc275bc44 100644
 --- a/django/core/handlers/asgi.py
 +++ b/django/core/handlers/asgi.py
 @@ -259,7 +259,7 @@ class ASGIHandler(base.BaseHandler):
                      'body': chunk,
                      'more_body': not last,
                  })
 -        await sync_to_async(response.close)()
 +        await sync_to_async(response.close, thread_sensitive=True)()

      @classmethod
      def chunk_bytes(cls, data):
 }}}

 I'm not sure why it doesn't help in Django 3.0, there is probably an extra
 issue.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31515#comment:27>
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.360c7c0f018edcc5195fdb1ee1e59013%40djangoproject.com.

Reply via email to