Index: src/wp-includes/wp-db.php
===================================================================
--- src/wp-includes/wp-db.php	(revision 27276)
+++ src/wp-includes/wp-db.php	(working copy)
@@ -1371,7 +1371,8 @@
 	/**
 	 * Check that the connection to the database is still up. If not, try to reconnect.
 	 *
-	 * If this function is unable to reconnect, it will forcibly die.
+	 * If this function is unable to reconnect, it will forcibly die before wp_head has been
+	 * triggered, or return false after wp_head has been triggered.
 	 *
 	 * @since 3.9.0
 	 *
@@ -1414,6 +1415,12 @@
 			sleep( 1 );
 		}
 
+		// If wp_head has already happened, wp_die()/dead_db() won't work properly,
+		// so let's just return and hope for the best.
+		if ( did_action( 'wp_head' ) ) {
+			return false;
+		}
+
 		// We weren't able to reconnect, so we better bail.
 		$this->bail( sprintf( ( "
 <h1>Error reconnecting to the database</h1>
@@ -1479,6 +1486,9 @@
 		if ( empty( $this->dbh ) || 2006 == $mysql_errno ) {
 			if ( $this->check_connection() ) {
 				$this->_do_query( $query );
+			} else {
+				$this->insert_id = 0;
+				return false;
 			}
 		}
 
