Closed Yannik closed 2 years ago
I'm a bit confused. Sometimes the leak occurs on first execution (no task with the same name exists), sometimes it only occurs on the second execution (task with the same name exists)
This is most likely related to https://github.com/ansible-collections/ansible.windows/issues/360. The output of Register-ScheduledJob
most likely contains a type that is either highly nested or contains a circular reference. This causes problems when trying to serialize the output to json. I'll have to have a look at it to see what property is causing that problem and find a way to avoid that.
Looks like the problem was something else. When a scheduled job already existed an error record is generated and the job definition is part of the error records TargetObject
property. The win_powershell
module serializes this property but doesn't try to sanitise the value like we do with other result values. The fix is to ensure the target_object
field also gets sanitised so it doesn't get stuck trying to serialize a highly nested object or an object with circular references. The fix for this is https://github.com/ansible-collections/ansible.windows/pull/386
SUMMARY
Running
Register-ScheduledJob
with an already existing-Name
in awin_powershell
task results in memory leak and high cpu usage on the target hosts. The task never ends, and even if cancelled on the controller node, the powershell process runs forever on the target node, resulting in total memory exhaustion.ISSUE TYPE
COMPONENT NAME
win_powershell
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
Host os: fedora 35 Target os: Windows Server 2022
STEPS TO REPRODUCE
Run this playbook twice. On the second run, the memory leak & cpu usage occurs.
Using
-FilePath
instead of-ScriptBlock
has the same result.EXPECTED RESULTS
Task should terminate with an error (as it does when executing the command without ansible), no memory leak should occur, and the task should be registered.
ACTUAL RESULTS
The task never terminates, and memory usage of the powershell.exe process on the target node is rising very quickly. Terminating the ansible process on the controller node does not result in the process being ended on the target node. Memory usage will rise until exhaustion:
(This is after about one minute)