ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aonis...@apache.org
Subject [1/2] ambari git commit: AMBARI-17539. Ambari Agent memory Leak fix. (aonishuk)
Date Fri, 01 Jul 2016 21:57:41 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.4 5ce2ca057 -> f5313cd5a
  refs/heads/trunk b92524547 -> 8e0f00f73


AMBARI-17539. Ambari Agent memory Leak fix. (aonishuk)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/8e0f00f7
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/8e0f00f7
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/8e0f00f7

Branch: refs/heads/trunk
Commit: 8e0f00f73dc2b3ada946516bdf580a53b804dd18
Parents: b925245
Author: Andrew Onishuk <aonishuk@hortonworks.com>
Authored: Sat Jul 2 00:57:32 2016 +0300
Committer: Andrew Onishuk <aonishuk@hortonworks.com>
Committed: Sat Jul 2 00:57:32 2016 +0300

----------------------------------------------------------------------
 .../src/main/python/ambari_agent/main.py         | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/8e0f00f7/ambari-agent/src/main/python/ambari_agent/main.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/main.py b/ambari-agent/src/main/python/ambari_agent/main.py
index 4db89f8..1fc445e 100644
--- a/ambari-agent/src/main/python/ambari_agent/main.py
+++ b/ambari-agent/src/main/python/ambari_agent/main.py
@@ -18,6 +18,25 @@ See the License for the specific language governing permissions and
 limitations under the License.
 '''
 
+def fix_subprocess_racecondition():
+  """
+  Subprocess in Python has race condition with enabling/disabling gc. Which may lead to turning
off python garbage collector.
+  This leads to a memory leak.
+  This function monkey patches subprocess to fix the issue.
+
+  !!! PLEASE NOTE THIS SHOULD BE CALLED BEFORE ANY OTHER INITIALIZATION was done to avoid
already created links to subprocess or subprocess.gc or gc
+  """
+  # monkey patching subprocess
+  import subprocess
+  subprocess.gc.isenabled = lambda: True
+
+  # re-importing gc to have correct isenabled for non-subprocess contexts
+  import sys
+  del sys.modules['gc']
+  import gc
+
+fix_subprocess_racecondition()
+
 import gc
 import traceback
 import threading


Mime
View raw message