-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
running ps1 script create temp file in everytime #11599
Comments
@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
|
i found command in /opt/microsoft/powershell/7-preview/pwsh . change and running the script,that temp files are still being created. |
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 |
Question is why it is used. |
Why what's used? $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 |
@SeeminglyScience My question is about scenario of the issue. |
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 |
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 PowerShell/src/System.Management.Automation/engine/remoting/common/RemoteSessionNamedPipe.cs Lines 553 to 566 in 70d4a89
(Follow It's implemented using |
Perhaps it is the case https://stackoverflow.com/questions/12126598/how-and-when-are-c-sharp-static-members-disposed
|
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.
|
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. |
@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 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. |
Noticed the same with Powerhell 7.1.4 and Centos7. Use powershell for monitoring and it generates a lot of them, fast. |
WG-Remoting |
@PaulHigin Makes sense to open issue in .Net Runtime repository? |
This is still happening for us, for PowerShell 7.2.3 on Ubuntu 20.04. Are we really having this issue due to telemetry or diagnostic reasons? If it's really a telemetry issue, I would like to understand the logic behind making Telemetry and Diagnostic ENABLED by default. I wonder who really uses them. How many developers actually ever needed them? I always think "Telemetry" or "Diagnostic" is something you enable when you think something is wrong. I understand that some reason you would like to keep telemetry ENABLED for everybody. But then you should be able to fix these issues earlier than 2 years. I disabled them with opt-out, but it's still causing lots of directories. I see that many people have the similar issue, so it means that something is wrong here. Maybe nobody uses PowerShell + .NET on Linux production machines and nobody cares. But we do. We trusted Microsoft, we migrated to Linux due to Linux support and we have these issues for a long time already. This might be not related with PowerShell, maybe a pure .NET issue. But we use PowerShell. So if there is a bug with .NET, I assume PowerShell team should open the issue. I will give it a try with PowerShell 7.3.0-preview.5. I hope newest beta version works. Fingers crossed. |
@PowerShell/powershell-committee We make a best effort to clean up listener named pipes on process exit, but it is not foolproof depending on how the process is exited. Windows cleans up all resources on process exit, including named pipes so we don't have the problem there. However, Linux apparently does not clean up these resources. The listener allows one local PowerShell process to connect and debug another PowerShell process. This is very convenient but is not needed all of the time, and on Linux machines ends up leaving named pipe files if the process is exited abruptly. I feel the best option is to make the pipeline listener opt-out through an optional command line switch ( /cc @SteveL-MSFT who first suggested making this opt-out. |
Actually we were having a similar problem on Windows as well. We converted our PowerShell services to Golang apps to avoid these issues, sadly. Here is the issue about that: So Windows was also not cleaning the temp files. It was eventually making production server unstable and crashing the apps. Then customer calls us and says our agent crashes their production servers. Even one time, due to thousand of these files on hundreds of servers, we were accused to make huge IO and bring their virtualmachine storage down. I strongly belive that these files should be created on request. We never need these files but they are keep generated and causes lots of troubles on the large customers. And simply we can not do a cleanup in their /tmp folder because we are afraid to remove a file which is necessary for Linux by mistake. Thank you for your understanding. |
Would it be possible to have it configured by a property in |
The listener is per process and not per runspace, so I didn't think it made sense to include it in InitialSessionState. Disabling the listener should probably just be an API for the hosted scenario. |
If it is for debug it is not clear why this should be opt-out but not out-in. |
How about naming the property in |
@iSazonov That will be a breaking change. |
Again, I feel the listener state should not be part of |
Breaking what? |
It's not broken on Windows as far as I know (files are cleaned up). A user may want to connect to a powershell process running in production and debug some issue, and making it opt-in will break that. |
If you look at the comments above, not only on Unix, but also on Windows, this feature leads to destruction of the production process. As result I don't think we should think of this feature as code. This feature should be enabled on demand just as we do to enable tracing. And we need an easy and convenient way to do that at any given moment. |
If you look into the issue mentioned in that comment, you will see that was about implicit remoting (remoteIPMoProxy_* files), not named piped. And it was fixed. |
I'm sorry that I mixed these two problems up. But the problem with remoteIPMoProxy_* is not completely solved. One example. ipmo dism
exit It's just that this module (ScheduleTask) has become Core compatible like so many others. |
@PowerShell/powershell-committee The PowerShell committee discussed this today, and regarding whether to make this named pipe connection feature But before this feature is made |
It seems it makes sense to open discussion in .Net Runtime repository - the issue is not PowerShell specific and comes from .Net workaround for named pipes on Unix. |
I investigated this some on an Ubuntu system, and PowerShell is not the only thing that creates and leaks named pipe files, when the process is abruptly terminated. The CLR creates three files in the users But I believe the dotNET CLR allows you to disable its named pipe files via an environment variable. We can do something similar with PowerShell to allow users to opt-out of creating the listener (and named pipe file) on PowerShell start up. This can be done via command parameter and with policy/configuration setting. |
Wanted to update the thread on my experience. Following guidance gleaned from dotnet/runtime#7204 for disabling the debugger FIFO pipes and the resulting https://learn.microsoft.com/en-us/dotnet/core/runtime-config/debugging-profiling page, I set two environment variables: COMPlus_EnableDiagnostics and DOTNET_EnableDiagnostics. Result was none of the three files were created after executing Powershell scripts in an alpine linux container. Environment variables I set:
|
update OS RHEL8.7
ENV
normal test
unusual exit
So ... the test results are the same as before. |
Cento7 and powershell-6.2.3-1.rhel.7.x86_64
create temp file in /tmp at running this script every time ,filename like CoreFxPipe_PSHost.[machine name].[num]+3.None.{scrptname}.ps1
The text was updated successfully, but these errors were encountered: