Problem/Motivation
When running Drupal on MySQL or Maria DB you can run in several errors that corrupt the database connection. Some examples for these kind of errors on the database layer are
1100 - Table 'xyz' was not locked with LOCK TABLES
1153 – Got a packet bigger than ‘max_allowed_packet’ bytes
- ...
If such an error happens, the MySQL server invalidates the connection and answers all further request through this connection by 2006 - MySQL server had gone away
.
Just have a look at https://www.google.com/search?q=site%3Adrupal.org+2006+MySQL+server+had+... to see that the drupal project is affected by that.
Again, 2006 - MySQL server had gone away
is not the error that causes an issue, it's the symptom you face after a different error happened. The causal error might be software bug in core or a contributed module or an inappropriate setup of the environment (for example the MySQL setup).
Normally you'll find details about the causal error in the logs. But if you use dblog, which is the most common in shared hosting environments, you won't find anything in the log because the log entry is not written due to the already invalidated connection.
If you also turned off error reporting on the site, all you get is a WSOD.
Proposed resolution
The solution to this problem is easy. The 2006 - MySQL server had gone away
error causes an Exception while wrinting to the log. If such an exception occurs we can simply open a second connection to the database and write the log entry again.
If you read through the comments, you'll notice that @Damien Tournoud already agreed on the proposed solution throughout the years for the different drupal versions:
Good idea, let's see how we can implement that in the new database layer.
Still applies to 8.x, which uses the default connection for watchdog messages.
Remaining tasks
Review and commit the existing patch.
User interface changes
None.
API changes
None.
The original issue description as posted for Drupal 6
If you read through different drupal bug reports you often see a quote likeTable 'watchdog' was not locked with LOCK TABLES
This could happen if you're using MySQL and a module requests a table lock and run into an error afterwards. In this case drupal is unable to store the error because it could not access the watchdog table.
I attached a patch that opens a dedicated database connection to write watchdog entries like I already proposed in these bug reports:
#298678: Impossible to lock two MySQL tables
#195812: db_error() doesn't work on default connection
Here are some issues related to this bug report:
#286176: Views causing error "Table 'watchdog' was not locked with LOCK TABLES'
#286380: Got past mem problem only to hit a timeout problem
#174705: Modify node type configuration storage to use a serialized collection stored in one variable rather than long variable names
#99718: user warning: Duplicate entry - work around available
Beta phase evaluation
Issue category | Bug because we don't display the right error and we display errors on the site while nothing is in the log |
---|---|
Issue priority | Major because ... Critical/Not critical because ... |
Prioritized changes | The main goal of this issue is a bug fix in the database error reporting. |