-
Notifications
You must be signed in to change notification settings - Fork 23.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ansible controller exponential memory usage when using handler listeners in collection #83392
Comments
Files identified in the description: None If these files are incorrect, please update the |
Looks like we just need to ensure we are operating on a copy of the diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py
index efd69efe9b..9cba974d07 100644
--- a/lib/ansible/plugins/strategy/__init__.py
+++ b/lib/ansible/plugins/strategy/__init__.py
@@ -558,7 +558,7 @@ class StrategyBase:
handler.fattributes.get('listen'),
listeners,
templar,
- )
+ ).copy()
if handler._role is not None:
for listener in listeners.copy():
listeners.extend([ |
Seems like that suggested fix works. |
I was wondering if we could/should take it a step further and just do the work of validating/extending |
Since this problem affects 2.17 as well as 2.18, it would be great if whichever PR is chosen is a candidate for backporting. I can't really tell whether @mkrizek 's #83400 or @ShawnHardwick 's #83393 is more or less of a candidate for that, just mentioning it since it's important to us and affecting all of our internal collection testing. |
Fixes ansible#83392 (cherry picked from commit cbbf068)
v2.17.1 ======= Minor Changes ------------- - ansible-test - Update ``pypi-test-container`` to version 3.1.0. Bugfixes -------- - Fix rapid memory usage growth when notifying handlers using the ``listen`` keyword (ansible/ansible#83392) - Fix the task attribute ``resolved_action`` to show the FQCN instead of ``None`` when ``action`` or ``local_action`` is used in the playbook. - Fix using ``module_defaults`` with ``local_action``/``action`` (ansible/ansible#81905). - fixed unit test test_borken_cowsay to address mock not been properly applied when existing unix system already have cowsay installed. - powershell - Implement more robust deletion mechanism for C# code compilation temporary files. This should avoid scenarios where the underlying temporary directory may be temporarily locked by antivirus tools or other IO problems. A failure to delete one of these temporary directories will result in a warning rather than an outright failure. - shell plugin - properly quote all needed components of shell commands (ansible/ansible#82535)
Summary
In Ansible
2.17
and2.18
, when using thelisten
parameter for handlers within an Ansible collection, the memory usage on the Ansible controller increases exponentially with the amount of handlers in the playbook. Depending on the playbook tasks, this can cause the Ansible controller to consume all memory on the host until the operating system handles the process by killing it.I believe the issue was introduce as part of this commit, which I will go into more detail in the reproduction steps:
#82854
Image of ansible-playbook consuming all memory right before the kernel sends a SIGKILL:
![20240603_171554_RemoteDesktopManager](https://private-user-images.githubusercontent.com/5496527/337350166-f8148195-f673-4096-a4c1-00652827b69c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk4MTQzMzgsIm5iZiI6MTcxOTgxNDAzOCwicGF0aCI6Ii81NDk2NTI3LzMzNzM1MDE2Ni1mODE0ODE5NS1mNjczLTQwOTYtYTRjMS0wMDY1MjgyN2I2OWMucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcwMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MDFUMDYwNzE4WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NjE1YmQzZmMyYWJmNDBhMzdiZGY3MWFkMzFhNDUyZjlhYjhiY2I2ZThmMjViN2RkNTkwZjgyMDgxNmNiZDYxMyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.xytsFdylqR4zNQM1c9cP3ZtLYQAVGaZDN_k7LeE2-Qw)
Only workaround I have at the moment is to use Ansible
2.16
or remove alllisten
parameter usage for handlers.Issue Type
Bug Report
Component Name
core
Ansible Version
Configuration
CONFIG_FILE() = /home/shawn.hardwick/.ansible.cfg
OS / Environment
Ansible controller:
PRETTY_NAME="Ubuntu 22.04.2 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.2 LTS (Jammy Jellyfish)"
Steps to Reproduce
Create a collection, lets name it
foo.test
.In this collection, create the following files:
roles/test_role/tasks/main.yml
roles/test_role/handlers/main.yml
Create a playbook, lets call it
playbook.yml
:Notes:
Execute the playbook with the below command:
ansible-playbook ./playbook.yml
In your process manager of preference, observe the memory usage of the ansible-playbook process.
I use
htop
.For some additional debugging context, I added the below
display.display
lines tolib/ansible/plugins/strategy/__init__.py
for additional context of what is happening to the array that is causing the memory leak:Expected Results
Memory usage to be small.
Actual Results
Memory is consumed until either the listeners are fully resolved (dependent on handler list) or the machine runs out of memory. On my machine, it will consume half of my total CPU and increasing RAM usage by 2GB every minute.
Using the
display.display
statements from the reproduce steps, the output might look like this:Code of Conduct
The text was updated successfully, but these errors were encountered: