Skip to content

Avoid caching ProviderInfo.FullName at init time - #11761

Closed
Ilya (iSazonov) wants to merge 2 commits into
PowerShell:masterfrom
iSazonov:fix-provider-drive-hidden
Closed

Avoid caching ProviderInfo.FullName at init time#11761
Ilya (iSazonov) wants to merge 2 commits into
PowerShell:masterfrom
iSazonov:fix-provider-drive-hidden

Conversation

@iSazonov

@iSazonov Ilya (iSazonov) commented Feb 3, 2020

Copy link
Copy Markdown
Collaborator

PR Summary

Address #9840

In #8831 we added caching for ProviderInfo.FullName. It came a problem in scenario of loading nested module. PowerShell change nested module name to root module name after it is loaded the nested module. In the scenario ProviderInfo.FullName is cached with nested module name and not updated to root module name.
The fix is to do not cache ProviderInfo.FullName at init time. After modules are loaded and cached name is safely used.

PR Context

PR Checklist

@daxian-dbw

Copy link
Copy Markdown
Member

Ilya (@iSazonov) Could you please update your PR description to include the summary and context?

@iSazonov Ilya (iSazonov) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Feb 4, 2020
@iSazonov Ilya (iSazonov) added this to the 7.1.0-preview.1 milestone Feb 4, 2020
@iSazonov

Copy link
Copy Markdown
Collaborator Author

Dongbo Wang (@daxian-dbw) Done.

@rjmholt

Copy link
Copy Markdown
Collaborator

Looking at the issue described, we might want to consider this for GA

moduleName,
name);
}
internal string GetFullName() => EvaluateFullName(Name, PSSnapInName, ModuleName);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It doesn't seem necessary to have the GetFullName function. You can call EvaluateFullName(Name, PSSnapInName, ModuleName) directly instead, no?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It is called in SessionStatePrividerAPIs too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If that's the case, can you maybe do this?

     internal string GetFullName()
     {
            string result = Name;
            if (!string.IsNullOrEmpty(PSSnapInName))
            {
                result =
                    string.Format(
                        System.Globalization.CultureInfo.InvariantCulture,
                        "{0}\\{1}",
                        PSSnapInName,
                        Name);
            }

            // After converting core snapins to load as modules, the providers will have Module property populated
            else if (!string.IsNullOrEmpty(ModuleName))
            {
                result =
                    string.Format(
                        System.Globalization.CultureInfo.InvariantCulture,
                        "{0}\\{1}",
                        ModuleName,
                        Name);
            }

            return result;
     }

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I can. Will do.

psSnapInName,
name);
}
return _fullName ?? (_fullName = GetFullName());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The name is still cached. But does it make sens to caching this name at all?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This comes from #8831 where we add the optimization. It is amazing to calculate the full name for every provider operation. I'd do not revert the optimization.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So it's not a problem to use the cached name in other places but only those 2 spots you changed in this PR?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It is important to do not cache the provider full name in the submodule until we set root module name.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Then it would be very helpful to add comments to the place where you use GetFullName() instead of the cached fullname, otherwise, another refactoring in future might change it back to use the cached value.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The comment is already there "Use GetFullName() to avoid caching full name at init time."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, yes, I missed that. Can you please also add the information about why to avoid the cached name?

@adityapatwardhan

Copy link
Copy Markdown
Member

Ilya (@iSazonov) Please add tests for the change.

There is no urgency to take this in 7.0 GA since it is not a regression from 6.2. We will consider this for GA if there are tests added to this PR and its merged by 10 am PDT on 02/12/2020. Otherwise we will consider this for the next servicing release of 7.

/cc Steve Lee (@SteveL-MSFT)

@iSazonov

Copy link
Copy Markdown
Collaborator Author

Aditya Patwardhan (@adityapatwardhan) Dongbo Wang (@daxian-dbw) Rob Holt (@rjmholt) Current fix is not reliable - later someone might accidentally violate these implicit conditions for using the cached name. I make more reliable fix in #11813 and add a test.

@rjmholt Rob Holt (rjmholt) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

To be closed in favour of #11813

@ghost ghost added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Feb 8, 2020
@adityapatwardhan

Copy link
Copy Markdown
Member

Ilya (@iSazonov) Can this PR be closed?

@TravisEz13

Copy link
Copy Markdown
Member

removing from GA-Consider to remove to from triage until it is ready to review

@iSazonov

Copy link
Copy Markdown
Collaborator Author

I think #11813 is better fix.

@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Feb 11, 2020
@iSazonov
Ilya (iSazonov) deleted the fix-provider-drive-hidden branch March 20, 2026 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

5 participants