#011038: eZP might go into an infinite loop if MySQL closes it connections causing apache to segfault

Description:

For reasons still unknown to me MySQL keeps closing connection every now and then.


Query error: MySQL server has gone away. Query: UPDATE ezsession
                    SET expiration_time='<timestamp>', data=<data>'
                    WHERE session_key='<key>'

These messages ends up in /var/log/error.log instead of /ezp-root/var/log/error.log. To see these messages do the following:


$ touch /var/log/error.log
$ chown <apache user> /var/log/error.log

In lib/ezdb/classes/ezmysqldb.php, if no result from the query is returned query() assumes something went wrong and calls $this->unlock(); which again calls $this->query();. If something wrongs happens while executing $this->unlock() it will be called again! This infinite loop will eventually cause Apache to crash with a "Segmentation Fault".

There are numerous reasons why MySQL might close the connection, some which might be eZP faults:
"You tried to run a query after closing the connection to the server. This indicates a logic error in the application that should be corrected."

However most of them is related to hosting environment and/or MySQL: http://dev.mysql.com/doc/refman/5.0/en/gone-away.htmlurl


Environment:

Operating System: Linux
PHP Version: (please be specific, like '4.4.3' or '5.1.5'): 4.4.4
Database and version: MySQL 4.1.14


- Attachments

No attachments for this issue.


- Comments

Commenting line 484: // $this->unlock(); in lib/ezdb/classes/ezmysqldb.php fixes the problem with segmentation faults. However this will only work if you are *not* using persistent connections.

#252966 by Ole Morten Halvorsen on June 28th, 2007 [Permanent Link]

1.
I was not able to reproduce it 'clean'. So I've hacked eZMySQLDB::query() and
put "$query = 'foo'" at first line. After that I've saw apaches seg.faults.

2.
The problem happens both in persistent and not persistent modes.(I've used site.ini.[DatabaseSettings].UsePersistentConnection=enabled/disabled

3.
Solution: I suggest to make direct sql query to unlock tables instead of doing it through eZMySQLDB:


- $this->query( "UNLOCK TABLES" );
+ mysql_query( "UNLOCK TABLES", $connection );

Fix works both for persistent and not persistent connections.

#253068 by Dmitry Lakhtyuk on July 16th, 2007 [Permanent Link]

fixed seg.faults by avoiding recursion.
trunk(3.10.0alpha1) rev. 19375
stable/3.9 (3.9.3) rev. 19376
stable/3.8 (3.8.9) rev. 19377

#253073 by Dmitry Lakhtyuk on July 17th, 2007 [Permanent Link]

The patch fixes the recursion issue, however if the connection has gone away the unlocking will not happen (as there is no connection). Not sure is this is an issue, but making a note of it just in case.

#256846 by Bruce Morrison on May 27th, 2008 [Permanent Link]

Ticket is closed but have you try to use mysql_ping to restart the connection

http://fr2.php.net/mysql_pingurl

#261439 by Stéphane Couzinier on April 30th, 2009 [Permanent Link]

bug also exists in mysqli db handler.

#264606 by Jostein Knudsen on February 11th, 2010 [Permanent Link]

Fixed in
trunk (4.3.0beta1) rev. 24902
stable/4.2 (4.2.1) rev. 24903
stable/4.1 (4.1.5) rev. 24904
stable/4.0 (4.0.8) rev. 24905

#264611 by Gunnstein Lye on February 11th, 2010 [Permanent Link]

- History
Properties
Type Bug
Priority High
Component Database related
Affects 3.8.8
3.9.2
Fix Versions 3.8.9
3.9.3
3.10.0alpha1
4.3.0beta1
Reporter Ole Morten Halvorsen
Responsible Gunnstein Lye
Status 0 Closed
Resolution Fixed
Created June 27th, 2007
Updated July 29th, 2010
Resolved February 11th, 2010
 
Navigation [Permanent Link]
Previous Issue
Back to Issues List
Next Issue: #019127
  DB Deadlocks on ezcontentobject_tree when updating subnode