Strange Errors when Using MySQL DB

69 views
Skip to first unread message

Bikramjeet Singh

unread,
Aug 20, 2021, 12:05:20 PM8/20/21
to Django users
I have a Django (v2.2.23) application connected to a MySQL (v5.7) database. Every now and then, for a few minutes at a time, all my DB queries start to fail with one of the following errors: "Unknown MySQL Error" (error code 2000), "InterfaceError", or "Malformed Packet" (error code 2027). The errors resolve themselves on their own after a few minutes, but then they pop up again a some time later (on average, every few hours). These errors happen seemingly at random and I haven't found any reliable way to reproduce them till now. There is nothing wrong with the code as far as I can see because when the queries do execute, they work as expected and give the correct results.

I have already made several attempts to fix the issue to no avail, including :-

This error is occuring both on local and staging environments.

In order to debug this further, I create a custom exception handler and logged the error as well as the last 3 SQL queries executed (which I got using connection.queries[-3:]).

The result is given below:

'EXCEPTION': InterfaceError(0, ''), 'LAST_QUERIES': [{'sql': 'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED', 'time': '0.000'}, {'sql': None, 'time': '0.000'}]

Notice that for the second query, the value of 'sql' is coming as None. Is Django trying to execute a null query? Could this be the cause of the strange, intermittent errors? Is this a bug inside Django or have I configured something incorrectly?


Jason

unread,
Aug 21, 2021, 8:32:32 AM8/21/21
to Django users
https://code.djangoproject.com/ticket/13906 might give some backgroud on this.  tl;dr its django setting the default transaction

the errors your seeing are mysql bugs, would it be possible to update to a newer version or at least the latest patch of 5.7?

Reply all
Reply to author
Forward
0 new messages