Homec4science

Fix an issue where closed connections are retained in a zombie state by PHP

Authored by epriestley <git@epriestley.com> on Jul 26 2012, 03:28.

Description

Fix an issue where closed connections are retained in a zombie state by PHP

Summary:
Argh, this took me like 4 hours to figure out.

After D3035, daemons on secure.phabricator.com are dying after a while with "too many open files". These aren't live MySQL connections (SHOW FULL PROCESSLIST shows nothing) but fds that haven't been completely disposed of (TCP connections in CLOSE_WAIT or unix sockets not doing much of anything). This repro'd on OSX and Ubuntu across many different versions of PHP, which I spent hours building since I'm dumb and made a mistake early on which led me to believe that I wasn't seeing it on OSX.

In fact, these connections don't close because we're still holding a reference to the result set (if we've executed any queries on the connection). Throw the result set away when we close a connection.

I missed this in D3035 originally because I inspected SHOW FULL PROCESSLIST but didn't consider to inspect lsof.

Test Plan: Built a script that does 300 connects, SELECT 1, and then does "lsof | grep getmypid() | wc -l". With the assignment commented out, it reports ~300 file descriptors. With the assignment there, it reports ~0 file descriptors.

Reviewers: btrahan, vrana, nh, dschleimer

Reviewed By: dschleimer

CC: aran

Maniphest Tasks: T1470

Differential Revision: https://secure.phabricator.com/D3071

Details

Committed
epriestley <git@epriestley.com>Jul 26 2012, 03:28
Pushed
aubortMar 17 2017, 12:03
Parents
rPHU0c40f1579956: Move querfyx() to libphutil
Branches
Unknown
Tags
Unknown

Event Timeline

epriestley <git@epriestley.com> committed rPHUd0b52ce31e13: Fix an issue where closed connections are retained in a zombie state by PHP (authored by epriestley <git@epriestley.com>).Jul 26 2012, 03:28