Homec4science

Fix a memory leak in PhabricatorGlobalLock

Authored by epriestley <git@epriestley.com> on Aug 10 2012, 20:28.

Description

Fix a memory leak in PhabricatorGlobalLock

Summary:
We currently cache all connections in LiskDAO so we can roll back transactions when fixtured unit tests complete.

Since we establish a new connection wrapper each time we establish a global lock, this cache currently grows without bound.

Instead, pool global lock connections so we never have more than the largest number of locks we've held open at once (in PullLocalDaemon, always 1).

Another way to solve this is probably to add an "onclose" callback to AphrontDatabaseConnection so that it can notify any caches that it been closed. However, we currently allow a connection to be later reopened (which seeems reasonable) so we'd need a callback for that too. This is much simpler, and this use case is unusual, so I'd like to wait for more use cases before pursing a more complicated fix.

Test Plan:
Ran this in a loop:

while (true) {
  for ($ii = 0; $ii < 100; $ii++) {
    $lock = PhabricatorGlobalLock::newLock('derp');
    $lock->lock();
    $lock->unlock();
  }
  $this->sleep(1);
}

Previously it leaked ~100KB/sec, now has stable memory usage.

Reviewers: vrana, nh, btrahan

Reviewed By: vrana

CC: aran

Maniphest Tasks: T1636

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

Details

Committed
epriestley <git@epriestley.com>Aug 10 2012, 20:28
Pushed
aubortJan 31 2017, 17:16
Parents
rPHb1b2afce9553: Support applications in aphrontpath.php
Branches
Unknown
Tags
Unknown

Event Timeline

epriestley <git@epriestley.com> committed rPH62b06f0f5dd7: Fix a memory leak in PhabricatorGlobalLock (authored by epriestley <git@epriestley.com>).Aug 10 2012, 20:28