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