Skip to content

Garbage in TMPDIR resulting in Failed to create CoreCLR, HRESULT: 0x80004005 #15299

Closed

Description

@alexei-matveev

Steps to reproduce

See comments in dotnet/runtime#46462

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.

Expected behavior

Empty output

Actual behavior

Garbage as this ist left:

        $ find 88a84cf3-05b5-40c3-a29e-52d611e919e7
        88a84cf3-05b5-40c3-a29e-52d611e919e7
        88a84cf3-05b5-40c3-a29e-52d611e919e7/.cache
        88a84cf3-05b5-40c3-a29e-52d611e919e7/.cache/powershell
        88a84cf3-05b5-40c3-a29e-52d611e919e7/.cache/powershell/StartupProfileData-NonInteractive
        88a84cf3-05b5-40c3-a29e-52d611e919e7/.cache/powershell/telemetry.uuid
        88a84cf3-05b5-40c3-a29e-52d611e919e7/.local
        88a84cf3-05b5-40c3-a29e-52d611e919e7/.local/share
        88a84cf3-05b5-40c3-a29e-52d611e919e7/.local/share/powershell
        88a84cf3-05b5-40c3-a29e-52d611e919e7/.local/share/powershell/Modules

Environment data

Same with the LTS 7.0.6 and non-LTS 7.1. CentOS 7 with MS Repo attached:

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.6
PSEdition                      Core
GitCommitId                    7.0.6
OS                             Linux 3.10.0-1127.19.1.el7.x86_64 #1 SMP Tue Aug 25 17:23:54 UTC 2020
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. added
    Needs-Triage
    on Apr 23, 2021
  2. added
    Needs-Repro
    on May 3, 2021
  3. daxian-dbw commented on May 3, 2021

    @daxian-dbw
    Member

    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?

  4. added
    WG-Engine
    and removed
    Needs-Repro
    on May 3, 2021
  5. alexei-matveev commented on May 6, 2021

    @alexei-matveev
    Author

    Yep, looks like that. This works as expected:

    mkdir xxx
    TMPDIR=./xxx pwsh
    

    This is the content wheil pwsh was running. They dissappear:

    prwx------ 1 alexei alexei 0 May  6 22:52 clr-debug-pipe-4432-226815218-in
    prwx------ 1 alexei alexei 0 May  6 22:52 clr-debug-pipe-4432-226815218-out
    srwxrwxr-x 1 alexei alexei 0 May  6 22:52 CoreFxPipe_PSHost.D742B9AE.4432.None.pwsh
    srw------- 1 alexei alexei 0 May  6 22:52 dotnet-diagnostic-4432-226815218-socket
    

    If I run it like this:

    TMPDIR=./xxx HOME=/nowhere pwsh
    

    Garbage remains in ./xxx:

    $ find .
    .
    ./b1409506-7aae-4211-b3c0-0d24ddbfbdf5
    ./b1409506-7aae-4211-b3c0-0d24ddbfbdf5/telemetry.uuid
    ./b1409506-7aae-4211-b3c0-0d24ddbfbdf5/StartupProfileData-Interactive
    ./b1409506-7aae-4211-b3c0-0d24ddbfbdf5/7.1.3
    ./b1409506-7aae-4211-b3c0-0d24ddbfbdf5/7.1.3/sentinel1-2021-5-6.done
    
  6. daxian-dbw commented on May 8, 2021

    @daxian-dbw
    Member

    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 Home defined.

  7. JamesWTruher commented on May 10, 2021

    @JamesWTruher
    Collaborator

    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.

  8. daxian-dbw commented on May 13, 2021

    @daxian-dbw
    Member

    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.

  9. added
    Issue-Bug
    and removed
    Needs-Triage
    on May 25, 2021
  10. iSazonov commented on Oct 15, 2021

    @iSazonov
    Collaborator

    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.

  11. added
    In-PR
    on Oct 18, 2021
  12. ghost removed
    In-PR
    on Nov 22, 2021
  13. ghost added
    Resolution-Fixed
    on Nov 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Issue-BugResolution-FixedWG-Engine

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions