Welcome Guest, Not a member yet? Register   Sign In
Transactions & Orphan MySQL connections
#1

[eluser]jonsolo11[/eluser]
Hi,

I'm running CI (w/PHP 5 & MySQL 5) on an internal development server. When my DB stopped working, I noticed there were ~40 connections from my CI username, all asleep, and some had been open for 10+ hours.

After a little work, I isolated the bug:

Normally in PHP, if I start a transaction and then there's a PHP error, PHP rolls back the transaction and closes the connection before dying.

CI's error handler, however, does not properly close the connection - and furthermore, the transaction is still open, so all the tables are locked.

This code (inside a Model) will throw a PHP Fatal Error and leave a hanging connection:
Code:
$this->db->query("start transaction");
not_a_function();

This code (again in a Model) will die() and clean up after itself properly:
Code:
$this->db->query("start transaction");
die();

This code (in plain PHP, outside of CI) will throw a Fatal Error, but will clean up:
Code:
$conn = mysql_connect("localhost", $user, $password);
mysql_query("start transaction");
not_a_function();

This code will die(), and will clean up also:
Code:
$conn = mysql_connect("localhost", $user, $password);
mysql_query("start transaction");
die();

This is a serious problem: it renders CI transaction-unsafe. It's not too problematic on a debug server, but it could be disastrous on a production server, as it could instantly lock up my database.


Messages In This Thread
Transactions & Orphan MySQL connections - by El Forum - 01-08-2008, 09:01 AM
Transactions & Orphan MySQL connections - by El Forum - 01-08-2008, 09:32 AM
Transactions & Orphan MySQL connections - by El Forum - 01-08-2008, 11:26 AM
Transactions & Orphan MySQL connections - by El Forum - 01-08-2008, 11:51 AM
Transactions & Orphan MySQL connections - by El Forum - 01-08-2008, 04:21 PM
Transactions & Orphan MySQL connections - by El Forum - 01-08-2008, 04:28 PM
Transactions & Orphan MySQL connections - by El Forum - 01-08-2008, 08:13 PM
Transactions & Orphan MySQL connections - by El Forum - 01-09-2008, 11:22 AM
Transactions & Orphan MySQL connections - by El Forum - 01-10-2008, 08:45 AM
Transactions & Orphan MySQL connections - by El Forum - 01-10-2008, 12:09 PM
Transactions & Orphan MySQL connections - by El Forum - 01-16-2008, 04:25 PM
Transactions & Orphan MySQL connections - by El Forum - 02-02-2008, 01:55 PM
Transactions & Orphan MySQL connections - by El Forum - 02-02-2008, 02:18 PM
Transactions & Orphan MySQL connections - by El Forum - 06-04-2009, 02:03 PM
Transactions & Orphan MySQL connections - by El Forum - 06-04-2009, 02:18 PM
Transactions & Orphan MySQL connections - by El Forum - 09-17-2009, 08:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB