[wp-trac] [WordPress Trac] #5932: wpdb should reconnect and retry query when "MySQL server has gone away"

WordPress Trac noreply at wordpress.org
Thu Jan 30 14:31:54 UTC 2014


#5932: wpdb should reconnect and retry query when "MySQL server has gone away"
---------------------------------+-----------------------
 Reporter:  dtc                  |       Owner:  pento
     Type:  task (blessed)       |      Status:  reopened
 Priority:  normal               |   Milestone:  3.9
Component:  Database             |     Version:  3.0
 Severity:  normal               |  Resolution:
 Keywords:  has-patch 3.9-early  |     Focuses:
---------------------------------+-----------------------
Changes (by pento):

 * milestone:  Future Release => 3.9


Comment:

 attachment:5932.4.diff​

 * Updates patch to apply cleanly against trunk
 * Changes a couple of the `mysql_*()` function calls to `@`-calls, as they
 generate error messages before we've had a chance to reconnect
 * Add some curly brackets to match WordPress coding style.
 * Add a unit test

 Replying to [comment:22 nacin]:
 > I'm noticing in [attachment:5932.diff] that there is a `return false`
 when the connection fails. But it's possible that the bail() doesn't
 result in a wp_die(). Then $wpdb->last_error isn't set, $wpdb->insert_id
 isn't reset, and we have various potential problems. How exactly should
 this work?

 The patch doesn't change existing behaviour. If `bail()` is called and
 `$wpdb->show_errors` is `false`, `$wpdb->error` is set, then the calling
 functions will return up to `wp-settings.php`. The next function call is
 `wp_set_wpdb_vars()`, which checks `$wpdb->error`, then will call
 `dead_db()`, which throws up the `<h1>Error establishing a database
 connection</h1>` message we all know and love.

 It wouldn't be a bad idea to revisit `bail()` and decide if it could be
 made to work nicer, but that seems out of scope for this ticket.

 This patch is feeling pretty close to ready, so some extra scrutiny would
 be greatly appreciated.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/5932#comment:33>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list