Skip to content
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

Use the same temp personal module path when env 'HOME' not defined #13239

Merged
merged 1 commit into from
Jul 23, 2020

Conversation

daxian-dbw
Copy link
Member

PR Summary

Fix #13189

When the env variable HOME is not defined, every Runspace startup on Unix platforms will try creating a folder in the form of /tmp/<new-guid>/.local/share/powershell/Modules as the personal user module path. That means LOTs of such folders get created when Foreach-Object -Parallel is dealing with a lot of inputs. In that situation, it may not be surprising to see strange failures like the DirectoryNotFoundException reported in the issue.

This PR adds a static field to cache the temporary personal user module path, so all Runspace's will use the same temp directory path in case HOME env variable is not defined.

PR Checklist

@rjmholt
Copy link
Collaborator

rjmholt commented Jul 22, 2020

N/A or can only be tested interactively

I wonder if it's possible to test this by unsetting $env:HOME

Copy link
Contributor

@PaulHigin PaulHigin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this! I don't think we need tests for this change, and as long as current tests pass I feel we are good.

@rjmholt
Copy link
Collaborator

rjmholt commented Jul 22, 2020

@PoshChan please remind me in 23 hours

@rjmholt rjmholt merged commit cfb1952 into PowerShell:master Jul 23, 2020
Comment on lines 254 to +258
string envHome = System.Environment.GetEnvironmentVariable(CommonEnvVariableNames.Home);
if (envHome == null)
{
envHome = GetTemporaryDirectory();
s_tempHomeDir ??= GetTemporaryDirectory();
envHome = s_tempHomeDir;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You assume that HOME could be defined on the fly (and preserve current behavior) but we could already put some files in previous folder :-(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry that I missed this comment. I think it would be very unlikely that the HOME env var changes it value after it's declared, so I'm not too worry about this.

@daxian-dbw daxian-dbw deleted the tempPath branch July 23, 2020 18:29
@PoshChan
Copy link
Collaborator

@rjmholt, this is the reminder you requested 23 hours ago

@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Jul 24, 2020
@iSazonov iSazonov added this to the 7.1.0-preview.7 milestone Jul 24, 2020
@iSazonov
Copy link
Collaborator

Will be this backported to 7.0?

@rjmholt
Copy link
Collaborator

rjmholt commented Jul 24, 2020

Will be this backported to 7.0?

@PaulHigin @daxian-dbw

@daxian-dbw daxian-dbw added the Review - Maintainer The PR/issue needs a review from the PowerShell repo Maintainers label Jul 24, 2020
@daxian-dbw
Copy link
Member Author

Good question. Maybe it's worth backporting, given the fix is so simple.
Marked this PR maintainer - review

@TravisEz13 TravisEz13 added BackPort-7.0.x and removed Review - Maintainer The PR/issue needs a review from the PowerShell repo Maintainers BackPort-7.0.x labels Aug 4, 2020
@TravisEz13 TravisEz13 modified the milestones: 7.1.0-preview.7, 7.1.0-preview.6 Aug 5, 2020
@ghost
Copy link

ghost commented Aug 17, 2020

🎉v7.1.0-preview.6 has been released which incorporates this pull request.:tada:

Handy links:

@ghost
Copy link

ghost commented Jan 19, 2021

🎉v7.0.4 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backport-7.0.x-Done CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log
Projects
None yet
Development

Successfully merging this pull request may close these issues.

System.IO.DirectoryNotFoundException using -Parallel feature and Microsoft.PowerShell.SDK
6 participants