Cento7 and powershell-6.2.3-1.rhel.7.x86_64
#!/bin/bin/pwsh
function xxx{
echo xxx
}
xxx
create temp file in /tmp at running this script every time ,filename like CoreFxPipe_PSHost.[machine name].[num]+3.None.{scrptname}.ps1
@nAnderYang Can you check and confirm with latest 7.0 build?
@iSazonov os: CentOS Linux release 7.7.1908 (Core)
@nAnderYang Sorry, I meant we need to repo with PowerShell 7.0 latest build.
@iSazonov update to github powershell-preview-7.0.0_rc.2-1.rhel.7.x86_64.rpm ,no command of pwsh
[root@test tmp]# rpm -qa|grep powershell
powershell-preview-7.0.0_rc.2-1.rhel.7.x86_64
[root@test tmp]# rpm -qa|grep powershell
-bash: pwsh: command not found
[root@test tmp]# which pwsh
/usr/bin/which: no pwsh in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
i found command in /opt/microsoft/powershell/7-preview/pwsh . change and running the script,that temp files are still being created.
no command of pwsh
It is by design to allow Side-By-Side scenario with stable version (pwsh vs pwsh-preview).
@rjmholt Have you any thoughts why the temp file is created?
Isn't that the named pipe used for IPC? e.g. for Enter-PSHostProcess
?
Question is why it is used.
Why what's used? Enter-PSHostProcess
? If you just mean why is a file created, that's how named pipes work on unix likes.
$pipe = $null
try {
$pipe = [IO.Pipes.NamedPipeServerStream]::new('mypipe')
Get-ChildItem /tmp/CoreFxPipe*
# Should show one with "mypipe" in the file name
} finally {
($pipe)?.Dispose()
}
The named pipe is created for PowerShell process to enable Enter-PSHostProcess
.
@SeeminglyScience My question is about scenario of the issue. Enter-PSHostProcess
is not mentioned and it is not clear is it used or not.
It's not created on demand, it's part of start up. The named pipe is there whether you use it or not, otherwise there would be no way for Enter-PSHostProcess
to signal the process it's trying to enter that it needs to create the pipe.
If the named pipe is created every pwsh startup this is answer to the issue question.
i used the scheduled task service, part of which is to control the working baseline of the windows virtual machine under the host through the pwsh script on the host. but over time, i discovered this problem. there are massive files in the / tmp path. the problem is that the files are generated during startup. why not destroy them when exiting?
I'd expect the pipe is disposed. @SeeminglyScience Do you know there it is created?
Yeah, it's created in the static ctor for RemoteSessionNamedPipeServer
:
(Follow CreateIPCNamedPipeServerSingleton
to see it create an instance of RemoteSessionNamedPIpe
and save it to a static prop)
It's implemented using NamedPipeServerStream
which has a finalizer so it should be doing the clean up on process exit. That's assuming non-Windows reliably runs finalizers, do you know if that's the case @iSazonov?
Perhaps it is the case https://stackoverflow.com/questions/12126598/how-and-when-are-c-sharp-static-members-disposed
Stack OverflowI have a class with extensive static members, some of which keep references to managed and unmanaged objects. For instance, the static constructor is called as soon as the Type is referenced, which
Hmm. I know on Windows finalizers are supposed to run when the process is closing, but iirc there is a timeout for the whole finalizer queue. So either that just doesn't happen on non-Windows (or maybe on core at all) or something is blocking the queue.
Either way, even if it does typically work, unless they removed the timeout for processing finalizers; this needs to hook into some process exiting event.
@nAnderYang Does it create (and not remove) a file every time the schedule task runs? And can you provide an example directory listing with file names and sizes? Can you see if it reproduces when running an empty script?
@iSazonov I don't have easy access to a unix machine to test this with, if you do can you verify that this repros by just starting and exiting?
@SeeminglyScience I have currently disabled this feature. However I created a test environment. This problem was reproduced.
Version powershell-6.2.3-1.rhel.7.x86_64 the situation is the same
[root@test tmp]# rpm -qa|grep powershell
powershell-preview-7.0.0_rc.2-1.rhel.7.x86_64
[root@test tmp]# rm -rf * /tmp
[root@test tmp]# echo '#!/opt/microsoft/powershell/7-preview/pwsh
function workthread{
echo hello
}
workthread'>/tmp/test.ps1
[root@test tmp]# chmod 700 /tmp/test.ps1
[root@test tmp]# for i in $(seq 1 10); do /tmp/test.ps1; done
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
[root@test tmp]# ls -lh /tmp
total 4.0K
srwxr-xr-x. 1 root root 0 Jan 19 09:47 CoreFxPipe_PSHost.D5CE6A72.1591.None.test.ps1
srwxr-xr-x. 1 root root 0 Jan 19 09:47 CoreFxPipe_PSHost.D5CE6A72.1615.None.test.ps1
srwxr-xr-x. 1 root root 0 Jan 19 09:47 CoreFxPipe_PSHost.D5CE6A73.1635.None.test.ps1
srwxr-xr-x. 1 root root 0 Jan 19 09:47 CoreFxPipe_PSHost.D5CE6A73.1656.None.test.ps1
srwxr-xr-x. 1 root root 0 Jan 19 09:47 CoreFxPipe_PSHost.D5CE6A74.1676.None.test.ps1
srwxr-xr-x. 1 root root 0 Jan 19 09:47 CoreFxPipe_PSHost.D5CE6A74.1695.None.test.ps1
srwxr-xr-x. 1 root root 0 Jan 19 09:47 CoreFxPipe_PSHost.D5CE6A74.1715.None.test.ps1
srwxr-xr-x. 1 root root 0 Jan 19 09:47 CoreFxPipe_PSHost.D5CE6A75.1734.None.test.ps1
srwxr-xr-x. 1 root root 0 Jan 19 09:47 CoreFxPipe_PSHost.D5CE6A75.1754.None.test.ps1
srwxr-xr-x. 1 root root 0 Jan 19 09:47 CoreFxPipe_PSHost.D5CE6A76.1774.None.test.ps1
-rwx------. 1 root root 92 Jan 19 09:47 test.ps1
[root@test tmp]#
It seems we need explicitly dispose the named pipe.
/cc @PaulHigin What do you think?
I can also confir this issue. I've just deleted about 40 000 files created by a job scheduled in cron.
Now, I have to implement a cron job to cleanup other cron jobs. 馃槪
I have this issue on v7.0.0 RC1-RTM, Debian Stretch arm7l with the arm32 package.
@KUTlime the bug was not fixed in v7.0.0 release.
@nAnderYang Yes, I can see the status Open and I can see thousands of files in my /tmp
folders.
I've just wanted to refresh this topic since the last entry was two months and four releases ago. Is there anybody who is actually doing something with this issue?
i don't know if anyone is following this bug. I will not close the isuse without being fixed.
Windows cleans up all resources when a process exits, including named pipes, but it looks like we can't rely on this for Linux systems. For Windows PowerShell we were using the CLR Appdomain unload event to dispose of the server pipe, but that is not implemented in dotNet core. We can use the ProcessExit event to do this for dotNet. That is not always reliable but i think it is our best bet.
Another idea is to make this named pipe listener opt-in. But this diminishes its usefulness somewhat for debugging.
Problem still exists
also sylog gets spammed by informational ps-messages
@MaFreiberger Please open new issues with repo steps and examples (screenshots)
Problem still exists
also sylog gets spammed by informational ps-messages
From: https://github.com/PowerShell/PowerShell/issues/6324#issuecomment-524233270
I am having this issue as well on Linux (RHEL 7) with 7.0.3. Thousands of CoreFxPipe_* files sitting in /tmp, with a new one created every time my cron job runs. Pwsh needs to clean up the pipes on exit, or have a startup option to prevent them from being created in a hosting/production environment. This needs to be fixed.
This is fixed in PowerShell 7.1. Please give 7.1.0-rc.1 a try to verify.
Most helpful comment
I can also confir this issue. I've just deleted about 40 000 files created by a job scheduled in cron.
Now, I have to implement a cron job to cleanup other cron jobs. 馃槪
I have this issue on v7.0.0 RC1-RTM, Debian Stretch arm7l with the arm32 package.