removed RunspaceConfiguration support#4942
Conversation
|
@SteveL-MSFT Did you change it to not depend on |
|
@daxian-dbw yes, I changed it to use InitialSessionState |
|
@SteveL-MSFT Awesome! Can you please point me to the part of changes that related to |
|
@daxian-dbw after ripping out the RunspaceConfig code, to get it working (and those tests passing) I create a ISS instance with defaults. |
PaulHigin
left a comment
There was a problem hiding this comment.
Not quite half way through the code review, but I am publishing the comments I have so far.
There was a problem hiding this comment.
Why was this error processing removed?
There was a problem hiding this comment.
From the code, it appears that this helper is only used with RunspaceConfiguration processing Format and Type data.
There was a problem hiding this comment.
I believe we still need this code. A test might look like:
"@
<Configuration>
<ViewDefinitions>
<View>
<Name>T2</Name>
</View>
</ViewDefinitions>
</Configuration>
@" > test.format.ps1xml
{ Update-FormatData test.format.ps1xml } | Should ThrowIn reply to: 142809956 [](ancestors = 142809956)
There was a problem hiding this comment.
I misunderstood the relationship between the formatdata code and the runspace config code. Will put it back and add the test.
There was a problem hiding this comment.
I tried this (fixing the @" "@ here string) and it doesn't throw on Beta.8.
There was a problem hiding this comment.
It does for me, Windows PowerShell and Beta 8 on Windows.
There was a problem hiding this comment.
repro'ing for me now, will add test
There was a problem hiding this comment.
Is this TODO comment valid anymore?
There was a problem hiding this comment.
I think the commend can be removed
There was a problem hiding this comment.
We do the same thing in the else block so we don't need this condition.
There was a problem hiding this comment.
Yes, will move it out
There was a problem hiding this comment.
Nitpick. I think this is easier to read if the condition expression is in parentheses: ... = (value != null) ? ...
There was a problem hiding this comment.
It looks like this constructor is no longer used (and the below ISS one is now only used). AuthorizationManager property is not assigned here and the code looks like it assumes it is never null, so I think we should remove this constructor.
There was a problem hiding this comment.
I'll check; if this isn't used anymore I'll remove it
There was a problem hiding this comment.
I don't understand why this was removed. It looks like the only purpose of this helper method is to write to file.
There was a problem hiding this comment.
PSConsoleFile is not supported as it was only used with RunspaceConfiguration
There was a problem hiding this comment.
But SaveAsConsoleFile() now no longer does anything useful. So I think this entire method should be removed.
There was a problem hiding this comment.
Yes, SaveAsConsoleFile() should be removed
There was a problem hiding this comment.
It looks like RemoveProvider on line 1523 should be removed too, since it is only used for RunspaceConfiguration.
There was a problem hiding this comment.
based on our code coverage that code has never been hit
There was a problem hiding this comment.
This may not be the same as creating a runspace with default RunspaceConfiguration and so the behavior may not be the same as before. [runspacefactory]::CreateRunspace($host). I don't know if this would make a noticeable difference but wanted to point it out.
There was a problem hiding this comment.
Yes, this is a breaking change. Our test coverage may not be sufficient to cover this so I need someone with experience here to point out how this may have adverse effects.
There was a problem hiding this comment.
If we want to mimic the existing behavior, then we should use InitialSessionState.CreateDefault() here. When using RunspaceConfiguration all built-in powershell modules are loaded as snapins, so you will get nothing when running Get-Module even after executing Get-Process. With CreateDefault(), built-in powershell modules are loaded as snapins as well. But with CreateDefault2(), only the Microsoft.PowerShell.Core is loaded as snapin and the rest are loaded as modules, like a regular powershell console session does.
There was a problem hiding this comment.
I think we should add an assert here to ensure InitialSessionState is never null.
There was a problem hiding this comment.
But SaveAsConsoleFile() now no longer does anything useful. So I think this entire method should be removed.
There was a problem hiding this comment.
Declaring and assigning result can now be done on one line. No need to have separate lines. Also can _initialSessionState be null here? The modified constructor above looks like it constructs this object without rsConfig and _initialSessionState is null.
There was a problem hiding this comment.
_initialSessionState is null after this constructor runs. Is this Ok?
There was a problem hiding this comment.
I'll create a default one
There was a problem hiding this comment.
Can this file just be removed? It looks like it only contains code related to runspace configuration.
There was a problem hiding this comment.
I think I originally wanted to remove it, but it contains an enum used by FormatAndTypeDataHelper which I think is still needed for some PSSnapins we ship even if we don't support custom PSSnapins
There was a problem hiding this comment.
You could rename - it's being used in Update-FormatData which is not snap-in related.
There was a problem hiding this comment.
Moving enum to FormatAndTypeDataHelper.cs and moving that file to utils. Removing the last of the RunspaceConfiguration*.cs files
There was a problem hiding this comment.
I take that back, RunspaceConfigurationEntry.cs is still needed. I'll move the enum to this file put it under engine. We can get rid of the minishell folder.
f032bd9 to
6121d89
Compare
|
@PowerShell/powershell-committee reviewed this and agreed on removal on RunspaceConfiguration code |
There was a problem hiding this comment.
This looks strange. Can you remove the bracket from the comment?
There was a problem hiding this comment.
Yes, that was probably just a mistake
There was a problem hiding this comment.
Are we sure that we want to use CreateDefault() and load all commands/functions? Or CreateDefault2() where just Core commands are loaded (and is faster)? Please add a comment to justify which default we use.
There was a problem hiding this comment.
This is where I need some expertise to mimic the previous RunspaceConfiguration behavior. @lzybkr @daxian-dbw ?
There was a problem hiding this comment.
I'm not sure this api makes sense anymore - it was accepting a runspace config, so the replacement would take an initial session state, but those apis already exist.
In reply to: 144347463 [](ancestors = 144347463)
There was a problem hiding this comment.
Are we sure that we want to use CreateDefault() and load all commands/functions? Or CreateDefault2() where just Core commands are loaded (and is faster)? Please add a comment to justify which default we use.
There was a problem hiding this comment.
Based on Jason's test, CreateDefault() is the faster one while CreateDefault2() does more, I'll update the comments on those methods
There was a problem hiding this comment.
Note that it feels like something is terribly wrong with CreateDefault2, so that's investigating. It should be faster like Paul suggested.
There was a problem hiding this comment.
I think that should be a separate issue. #5104
There was a problem hiding this comment.
I'd move this code earlier, like in main. I needed similar code in the past and never noticed it here.
My version was little nicer, waiting for the debugger to attach (in a loop, with time outs) and then hit a breakpoint.
There was a problem hiding this comment.
Is this code needed anymore? In VSCode, it will break in main() anyways. Plus this code looks to be an artifact of when ISS was new as it's blocking at the creation of ISS.
There was a problem hiding this comment.
Sometimes you need to launch from another process, so it can be useful. But you could just remove it and the next time it's needed, something like it will come back.
PaulHigin
left a comment
There was a problem hiding this comment.
I was surprised that CreateDefault2() was so much slower creating commands than with CreateDefault() initialization. I believe you said somewhere that you created an Issue to track this perf issue.
daxian-dbw
left a comment
There was a problem hiding this comment.
I'm now looking at ConnectionFactory.cs, but want to share my existing feedback early.
There was a problem hiding this comment.
Is it safe to remove the enum number SearchState.SearchingBuiltinScripts? It doesn't seem to be needed anymore.
There was a problem hiding this comment.
Yes, looks safe to remove as it's no longer being used
There was a problem hiding this comment.
It looks to me it's always SingleShell now, as InitialSessionState is initialized in the constructor and cannot be null.
So, all IsSingleShell related the code can be cleaned as well.
There was a problem hiding this comment.
It looks to me we can remove the set method now, as it's only used for a RunspaceConfiguration scenario.
There was a problem hiding this comment.
looks like InitialSessionState.cs:3582 uses it
There was a problem hiding this comment.
SpecialVariables.ConsoleFileName in SpecialVariables.cs can be removed now
There was a problem hiding this comment.
The if statement looks to me is checking if the current EngineSessionState is a module session state and if the module defines providers. This seems will happen when a Runspace is closing while running cmdlets from a module.
RemoveProvider(string providerName, bool force, CmdletProviderContext context) doesn't look like solely related to RunspaceConfigration.
I think we should keep this method but remove the extra loop.
There was a problem hiding this comment.
Same question here. This method doesn't look like solely related to RunspaceConfiguration.
There was a problem hiding this comment.
These following two methods seem OK to be removed:
private void RemoveProvider(ProviderConfigurationEntry entry)
private string GetProviderName(ProviderConfigurationEntry entry)
There was a problem hiding this comment.
This change seems unnecessary. The extra space should be removed.
There was a problem hiding this comment.
If we want to mimic the existing behavior, then we should use InitialSessionState.CreateDefault() here. When using RunspaceConfiguration all built-in powershell modules are loaded as snapins, so you will get nothing when running Get-Module even after executing Get-Process. With CreateDefault(), built-in powershell modules are loaded as snapins as well. But with CreateDefault2(), only the Microsoft.PowerShell.Core is loaded as snapin and the rest are loaded as modules, like a regular powershell console session does.
There was a problem hiding this comment.
Same here, if we want to mimic the existing behavior, then we should use CreateDefault.
There was a problem hiding this comment.
Sorry if you already explained this change in some previous conversations, but I didn't find any.
The original code seems already makes sure that StopAllTranscribing will be called only if all runspaces are at closing state. As for AmsiUtils.Uninitialize(), it looks to me doesn't need to be called for every Runspace close operation, but stead should only be called once when the last Runspace is closed.
There was a problem hiding this comment.
@lzybkr had a question about this section in that previously it would return out of this method early
if it's not the last runspace so that transcription would not be stopped. Because it returned early, the rest of the closing actions would not be executed.
There was a problem hiding this comment.
The rest of the closing method is AmsiUtils.Uninitialize(); which I think should only execute once when the last Runspace is closing. It looks to me AmsiUtils.Init() should run only once and then can be shared across all Runspaces.
There was a problem hiding this comment.
I remember AMSI is thread safe and @PaulHigin even fixed a bug previously to remove the locks when calling AmsiUtils.ScanContent. So I think it should be initialized once and used across all Runspaces.
There was a problem hiding this comment.
I'll change it so if there's no open runspaces left, transcription is stopped and AmsiUtils.Uninitialize() is called.
There was a problem hiding this comment.
Same here. If we want to mimic RunspaceConfiguration, then CreateDefault() should be used.
There was a problem hiding this comment.
I think this method should be removed, and update the two call sites in HelpProviderWithFullCache.cs:
if (!this.CacheFullyLoaded || AreSnapInsSupported()) ==> if (!this.CacheFullyLoaded)
There was a problem hiding this comment.
will update and remove no longer relevant comment
There was a problem hiding this comment.
I just ran into a scenario where I need this flag to help debugging: I want to debug the module path resolution code in ModuleIntrisics.cs when starting powershell core in Windows PowerShell. I cannot just start/debug powershell core in VSCode, as I need to start it from Windows PowerShell, and -isswait is very helpful in this situation.
So I think we probably should keep this hidden flag for debugging purpose.
There was a problem hiding this comment.
When I needed it, I needed it even earlier than this, so I never saw this code.
A slightly nicer version does something like:
while (!System.Diagnostics.Debugger.IsAttached) {
Thread.Sleep(100);
}
System.Diagnostics.Debugger.Break();This way, you don't need to press a key.
There was a problem hiding this comment.
I'll put in the updated version Jason is suggesting
There was a problem hiding this comment.
AmsiUtils.Uninitialize() should be called even if host == null.
It looks to me we don't need to change this method. Here is the logic of the existing method:
- if there is still an open Runsapce, then this method will just return;
- if there is no open Runspace, then the method will continue: call
StopAllTranscribingifhost != null, and then callAmsiUtils.Uninitialize().
There was a problem hiding this comment.
will revert previous change
There was a problem hiding this comment.
How about change it to the following to remove 2 duplicate lines of InitialSessionState.CreateDefault2()?
#if DEBUG
if (args.Length > 0 && !String.IsNullOrEmpty(args[0]) && args[0].Equals("-isswait", StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("Attach the debugger to continue...");
while (!System.Diagnostics.Debugger.IsAttached) {
Thread.Sleep(100);
}
System.Diagnostics.Debugger.Break();
}
#endif
ConsoleHost.DefaultInitialSessionState = InitialSessionState.CreateDefault2();
|
There is also a comment at #4942 (comment). |
c960aeb to
5bcabfa
Compare
daxian-dbw
left a comment
There was a problem hiding this comment.
LGTM. Thanks @SteveL-MSFT for getting this done!
New commits have been pushed to address comments.
5bcabfa to
744f495
Compare
744f495 to
955b412
Compare
|
New Update-FormatData with invalid xml is causing a problem with PowerShellGet tests to fail. I repro'd it with binaries built from master so it's not the result of these changes. Created #5154 to track. |
…PI documentation Updated the 2 unit tests accordingly with Runspaceconfiguration removal PowerShell#4942
For PSCore6, we are only supporting InitialSessionState. The RunspaceConfiguration api was already made internal. This PR removes all the code related to RunspaceConfiguration. This also means that some public apis have changed. Was deciding between leaving the RunspaceConfiguration parameters and throwing Unsupported, but thought it was better to have it a compile time error. This should simplify the code base.