I am stuck with the following problem: we have an app that runs an continuous loop opening remote connection via powershell (performing some actions and then closing). This works fine in a Windows machine but not in Linux ones (tested on Ubuntu 16.0.4
).
Use the the script below to reproduce the problem:
$i = 0
while ($i -le 200)
{
$password = "myPassword"
$domain = "domain\computerName"
$computerName = "xxx.xxx.xxx.xxx"
$pwSession = convertto-securestring -AsPlainText -Force $password
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $domain,$pwSession
$session = new-pssession -computername $computerName -credential $cred -Authentication Negotiate
Remove-PSSession -Session $session
Get-PSSession
sleep 3
$i
$i++
}
- enter a powershell context by running
pwsh
- run the script above (copy + paste)
- run
top -p {process id}
on the pwsh process id (you can run it in a single step withtop -p $(ps -aux | grep pwsh | head -n 1 | cut -d' ' -f5)
You will see a window like
You will notice the memory consumption will keep growing (by 0.1 percent at each iteration), indefinitely.
Google does return a couple of posts mentioning memory leaks in opening new sessions with powershell, but I could not find in any of them an explanation on why the simple script above would create such an issue - again, in linux, only.
Any ideas in how tackle this issue ?
pgrep
instead of trying to parseps
:top -p $(pgrep -f pwsh)
.