You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Garbage in TMPDIR resulting in Failed to create CoreCLR, HRESULT: 0x80004005 #15299
Hm, it seems it is difficult to reproduce from an interactive Shell.
The automated Script is started from a daemon process, several times a minute ...
...
ls -lrtd /tmp/????????-????-????-????-????????????
[Edited by Dongbo Wang (@daxian-dbw)] Remove the Home env variable, and then start PowerShell multiple times. You will see multiple temporary folder with GUID id names got created in /tmp.
I believe this is related to #13239. PowerShell creates a temporary folder when the environment variable Home doesn't exist. Can you try setting the env variable Home and see if the issue is gone?
there's a few things going on here: we create a fair number of files (command cache, for one, which we want to remain after the process is gone). It's possible to disable telemetry, but that's only one file. Some of these things are artifacts of the way we enable debugging. Usually, these files aren't really a problem, but in some edge cases they may be. I would suggest that the appropriate way to proceed is to launch something like mkdir /tmp/t; HOME=/tmp/t TMPDIR=/tmp/t pwsh; rm -rf /tmp/t
I thought this was instructive:
# TMPDIR=/dev/null pwsh
Failed to create CoreCLR, HRESULT: 0x80004005
# HOME=/dev/null pwsh
Process terminated. The type initializer for 'System.Management.Automation.Runspaces.InitialSessionState' threw an exception.
at System.Environment.FailFast(System.String, System.Exception)
at Microsoft.PowerShell.UnmanagedPSEntry.Start(System.String, System.String[], Int32)
at Microsoft.PowerShell.ManagedPSEntry.Main(System.String[])
System.TypeInitializationException: The type initializer for 'System.Management.Automation.Runspaces.InitialSessionState' threw an exception.
---> System.TypeInitializationException: The type initializer for 'System.Management.Automation.Platform' threw an exception.
---> System.IO.IOException: The file '/dev/null' already exists.
at System.IO.FileSystem.CreateDirectory(String fullPath)
at System.IO.Directory.CreateDirectory(String path)
at System.Management.Automation.Platform.SelectProductNameForDirectory(XDG_Type dirpath)
at System.Management.Automation.Platform..cctor()
--- End of inner exception stack trace ---
at System.Management.Automation.Runspaces.InitialSessionState..cctor()
--- End of inner exception stack trace ---
at System.Management.Automation.Runspaces.InitialSessionState.CreateDefault2()
at Microsoft.PowerShell.ConsoleShell.Start(String bannerText, String helpText, String[] args)
at Microsoft.PowerShell.UnmanagedPSEntry.Start(String consoleFilePath, String[] args, Int32 argc)Aborted
Let's address the second case first. Here we can see that the CLR is up and clearly running our code. The engine attempts to create a directory for config data in the users home (CorePsPlatform.cs lines 321, 346, and elsewhere) which will obviously fail in my case. We could possibly be a bit more robust in this case. However, because we use the home location for things like command cache, not having it is going to result in some problematic performance (just a gut response). However, I'm going to assert that setting TMPDIR=/dev/null produces a much more dramatic result - it looks like the CLR fiddles about and if it can't do what it needs, it just falls over. I don't think we get as far as executing any of our code.
FWIW, I think this is probably an issue best addressed by documentation.
I thought about this issue more, and believe we should fix it in our code to make PowerShell work better in a container environment without the env variable Home defined. After all, it's not uncommon for a container to not have Home env var. I think it can be fixed by adding a well-known prefix to the temporary folder name, and next time PS session starts, it can just look for an folder under tmp with that well-know prefix and use that as the pseudo Home directory.
Activity
daxian-dbw commentedon May 3, 2021
I believe this is related to #13239. PowerShell creates a temporary folder when the environment variable
Homedoesn't exist. Can you try setting the env variableHomeand see if the issue is gone?alexei-matveev commentedon May 6, 2021
Yep, looks like that. This works as expected:
This is the content wheil pwsh was running. They dissappear:
If I run it like this:
Garbage remains in ./xxx:
daxian-dbw commentedon May 8, 2021
James Truher (@JamesWTruher) Rob Holt (@rjmholt) Any ideas on how to address this in code? Or, do we just document this behavior?
It's not uncommon for containers to not have
Homedefined.JamesWTruher commentedon May 10, 2021
there's a few things going on here: we create a fair number of files (command cache, for one, which we want to remain after the process is gone). It's possible to disable telemetry, but that's only one file. Some of these things are artifacts of the way we enable debugging. Usually, these files aren't really a problem, but in some edge cases they may be. I would suggest that the appropriate way to proceed is to launch something like
mkdir /tmp/t; HOME=/tmp/t TMPDIR=/tmp/t pwsh; rm -rf /tmp/tI thought this was instructive:
Let's address the second case first. Here we can see that the CLR is up and clearly running our code. The engine attempts to create a directory for config data in the users home (CorePsPlatform.cs lines 321, 346, and elsewhere) which will obviously fail in my case. We could possibly be a bit more robust in this case. However, because we use the home location for things like command cache, not having it is going to result in some problematic performance (just a gut response). However, I'm going to assert that setting
TMPDIR=/dev/nullproduces a much more dramatic result - it looks like the CLR fiddles about and if it can't do what it needs, it just falls over. I don't think we get as far as executing any of our code.FWIW, I think this is probably an issue best addressed by documentation.
daxian-dbw commentedon May 13, 2021
I thought about this issue more, and believe we should fix it in our code to make PowerShell work better in a container environment without the env variable
Homedefined. After all, it's not uncommon for a container to not haveHomeenv var. I think it can be fixed by adding a well-known prefix to the temporary folder name, and next time PS session starts, it can just look for an folder undertmpwith that well-know prefix and use that as the pseudoHomedirectory.iSazonov commentedon Oct 15, 2021
Dongbo Wang (@daxian-dbw) See dotnet/runtime#2048. I did a proposal there and draft implementation. We could ask .Net team to include the API in .Net Runtime 7.