#35812: 2006 'MySQL server has gone away' error after idle period in Django app
polling Kafka
-------------------------------------+-------------------------------------
Reporter: Adithya Kaade | Type:
Arvind | Uncategorized
Status: new | Component:
| Uncategorized
Version: 4.2 | Severity: Normal
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
-------------------------------------+-------------------------------------
**Issue Summary:**
In a custom Django app, a 2006: 'MySQL server has gone away' error occurs
when querying the MySQL database after an idle period. The app polls
messages from a Kafka topic with low traffic, so after a long idle period,
the first query to the MySQL database fails with this error. However,
immediately after the failure, subsequent queries succeed without issue.
**Steps to Reproduce:**
Create a custom Django app using python manage.py startapp.
Inside the app, implement an infinite loop to poll messages from a
Kafka topic.
Messages are rarely inserted into the Kafka topic.
After a long idle period, when a new message is received and the app
tries to query the MySQL database, the first query fails with the error
(2006, 'Server has gone away').
Immediately after this failure, subsequent queries succeed without any
errors.
**Expected Behavior:**
When CONN_HEALTH_CHECKS = True is set, the connection to the database
should be checked and re-established before the query is executed,
preventing the error.
Actual Behavior:
The first query fails with a 2006: 'MySQL server has gone away' error
after an idle period.
Setting CONN_HEALTH_CHECKS = True did not resolve the issue.
Setting CONN_MAX_AGE = 30 also did not prevent the error.
All subsequent queries after the first failure succeed immediately
without issues.
**Environment:**
Django Version: 4.2.13
Python Version: 3.10.14
MySQL Version: 8.0
**Additional Information:**
The issue only occurs for the first query after an idle period;
subsequent queries work as expected.
Tested with both CONN_HEALTH_CHECKS and CONN_MAX_AGE settings, but the
issue persists.
--
Ticket URL: <https://code.djangoproject.com/ticket/35812>
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/010701925588ac99-d56acb09-f571-429f-89c4-0e6bcb860d34-000000%40eu-central-1.amazonses.com.