Skip to content

Assign null to self::$_db on reset_db to ensure PDO closes the connections#338

Merged
treffynnon merged 1 commit intoj4mie:developfrom
ninjacato:master
May 30, 2018
Merged

Assign null to self::$_db on reset_db to ensure PDO closes the connections#338
treffynnon merged 1 commit intoj4mie:developfrom
ninjacato:master

Conversation

@ninjacato
Copy link
Contributor

I discovered by running SHOW PROCESSLIST in MySQL that even though I executed \ORM::reset_db() the connections were still hanging and wouldn't be closed until MySQL closed them. This was causing errno=32 Broken pipe errors when using Idiorm with a long running script. Even though self::$_db is assigned a new array, not assigning null seems to make PDO try to reuse old connections, which had been closed by MySQL, causing the aforementioned Broken pipe error. To make sure PDO closes connections they must be set to null, from the docs:

To close the connection, you need to destroy the object by ensuring that all remaining references to it are deleted—you do this by assigning NULL to the variable that holds the object.

Setting self::$_db to null before assigning a new array ensured that PDO did really close the connection on \ORM::reset_db() and I verified it on MySQL using SHOW PROCESSLIST, and by the absence of errors in my script.

@treffynnon
Copy link
Collaborator

Thank you for the pull request. I'll merge and prepare a release shortly.

@treffynnon treffynnon changed the base branch from master to develop May 30, 2018 23:51
@treffynnon treffynnon merged commit 6bba7f6 into j4mie:develop May 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants