Skip to content

Conversation

@iSazonov
Copy link
Collaborator

@iSazonov iSazonov commented Feb 3, 2020

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
Member

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

@iSazonov 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 iSazonov added this to the 7.1.0-preview.1 milestone Feb 4, 2020
@iSazonov
Copy link
Collaborator Author

iSazonov commented Feb 4, 2020

@daxian-dbw Done.

@rjmholt
Copy link
Collaborator

rjmholt commented Feb 5, 2020

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

@iSazonov iSazonov modified the milestones: 7.1.0-preview.1, GA-consider Feb 5, 2020
moduleName,
name);
}
internal string GetFullName() => EvaluateFullName(Name, PSSnapInName, ModuleName);
Copy link
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
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
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
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
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
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
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
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
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
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
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
Member

@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 @SteveL-MSFT

@iSazonov
Copy link
Collaborator Author

iSazonov commented Feb 8, 2020

@adityapatwardhan @daxian-dbw @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.

Copy link
Collaborator

@rjmholt rjmholt left a comment

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
Member

@iSazonov Can this PR be closed?

@TravisEz13
Copy link
Member

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

@iSazonov
Copy link
Collaborator Author

I think #11813 is better fix.

@iSazonov iSazonov closed this Feb 11, 2020
@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
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