Closed Yannik closed 2 years ago
Thanks for the bug report, the trouble here is that Get-Content
returns a string for every line but each of those strings contain extended properties. The code currently doesn't inspect those so it's applying the depth restrictions it should be. When Ansible goes to finally serialize that object it comes across the PSProvider property which has recursive nesting causing PowerShell to just eventually run out of memory as it's constantly trying to serialize the data.
I see 2 options available here:
The first will be the simplest but people could be expecting the ETS members to be present whereas the second option acts more like ConvertTo-Json
does in PowerShell today. I'll have to think this through and figure out what the best step would be to continue here.
In the meantime as a workaround I recommend you change the Get-Content
to [System.IO.File]::ReadAllLines("$env:temp\test.log")
.
I ended up going for option 1 and stripping out the ETS properties for these primitive types. The PR for this is https://github.com/ansible-collections/ansible.windows/pull/373.
SUMMARY-
Assigning the result from
Get-Content
to$Ansible.Result
inwin_powershell
results in memory leak on the target host. 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 11 Enterprise 21H2, build 22000.675
STEPS TO REPRODUCE
EXPECTED RESULTS
Task should terminate, no memory leak should occur, and the result is correctly returned to the ansible controller
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 3-5 minutes. Running the task again results in an additional powershell.exe process also quickly ramping up to memory exhaustion.