#35812: 2006 'MySQL server has gone away' error after idle period in Django app
polling Kafka
-------------------------------------+-------------------------------------
Reporter: Adithya Kaade | Owner: (none)
Arvind |
Type: Bug | Status: closed
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: 2006 'MySQL server | Triage Stage:
has gone away' | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):
* resolution: => invalid
* status: new => closed
Comment:
Please refer to the
[https://docs.djangoproject.com/en/5.1/ref/databases/#caveats database
documentation about caveats]
> If a connection is created in a long-running process, outside of
Django’s request-response cycle, the connection will remain open until
explicitly closed, or timeout occurs. You can use
`django.db.close_old_connections()` to close all old or unusable
connections.
In other words, outside of the request-response cycle Django has no entry
point to determine when the connection should be ping'ed to determine if
it should be closed and re-opened and performing a ping before every
single query is not desirable so `CONN_HEALTH_CHECKS`
[https://docs.djangoproject.com/en/5.1/ref/settings/#conn-health-checks
has no effect there].
> If set to True, existing persistent database connections will be health
checked before they are reused **in each request** performing database
access.
You should explicitly `close_old_connections` before every code path
outside of request-response cycle that interacts with the database and
could be idling for longer than your configured connection timeouts. In
your case, being a Kafka consumer, I assume that would be every time you
consume a new message.
--
Ticket URL: <https://code.djangoproject.com/ticket/35812#comment:5>
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/01070192573f2b5a-4ca7eea1-a809-4fbd-ad6a-dc9ef056eff9-000000%40eu-central-1.amazonses.com.