Friday, August 20, 2021

Strange Errors when Using MySQL DB

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?


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f81df377-2ddf-4b18-89e1-8991b028dea2n%40googlegroups.com.

No comments:

Post a Comment