Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
removed RunspaceConfiguration support #4942
Conversation
SteveL-MSFT
assigned
daxian-dbw
Sep 28, 2017
SteveL-MSFT
requested review from
daxian-dbw and
lzybkr
Sep 28, 2017
SteveL-MSFT
requested review from
adityapatwardhan,
anmenaga,
BrucePay,
dantraMSFT,
Francisco-Gamino,
JamesWTruher,
mirichmo,
PaulHigin and
vors
as
code owners
Sep 28, 2017
|
@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. |
SteveL-MSFT
added
Breaking-Change
Review - Committee
labels
Sep 29, 2017
PaulHigin
requested changes
Oct 4, 2017
Not quite half way through the code review, but I am publishing the comments I have so far.
| @@ -1055,11 +985,6 @@ protected override void ProcessRecord() | ||
| if (entries.Count > 0) | ||
| { | ||
| Context.FormatDBManager.UpdateDataBase(entries, this.Context.AuthorizationManager, this.Context.EngineHostInterface, false); | ||
| - FormatAndTypeDataHelper.ThrowExceptionOnError( |
SteveL-MSFT
Oct 4, 2017
Owner
From the code, it appears that this helper is only used with RunspaceConfiguration processing Format and Type data.
lzybkr
Oct 12, 2017
Member
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)
SteveL-MSFT
Oct 13, 2017
Owner
I misunderstood the relationship between the formatdata code and the runspace config code. Will put it back and add the test.
SteveL-MSFT
Oct 13, 2017
Owner
I tried this (fixing the @" "@ here string) and it doesn't throw on Beta.8.
| - shellId = _configuration.ShellId; | ||
| - else | ||
| - shellId = "Microsoft.PowerShell"; // TODO: what will happen for custom shells built using Make-Shell.exe | ||
| + shellId = "Microsoft.PowerShell"; // TODO: what will happen for custom shells built using Make-Shell.exe |
| - configuration = null; | ||
| - } | ||
| -#else | ||
| + if (args.Length > 0 && !String.IsNullOrEmpty(args[0]) && args[0].Equals("-iss", StringComparison.OrdinalIgnoreCase)) |
PaulHigin
Oct 4, 2017
Contributor
We do the same thing in the else block so we don't need this condition.
| set | ||
| { | ||
| - if (this.RunspaceConfiguration != null) | ||
| - throw new NotImplementedException("set_TypeTable()"); | ||
| _typeTable = value; | ||
| _typeTableWeakReference = value != null ? new WeakReference<TypeTable>(value) : null; |
PaulHigin
Oct 4, 2017
Contributor
Nitpick. I think this is easier to read if the condition expression is in parentheses: ... = (value != null) ? ...
| - /// RunspaceConfiguration information | ||
| - /// </param> | ||
| - internal ExecutionContext(AutomationEngine engine, PSHost hostInterface, RunspaceConfiguration runspaceConfiguration) | ||
| + internal ExecutionContext(AutomationEngine engine, PSHost hostInterface) |
PaulHigin
Oct 4, 2017
Contributor
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.
| @@ -5070,9 +5069,6 @@ internal void SaveAsConsoleFile(string path) | ||
| { | ||
| throw PSTraceSource.NewArgumentException("path", ConsoleInfoErrorStrings.BadConsoleExtension); | ||
| } | ||
| - |
PaulHigin
Oct 4, 2017
Contributor
I don't understand why this was removed. It looks like the only purpose of this helper method is to write to file.
SteveL-MSFT
Oct 4, 2017
Owner
PSConsoleFile is not supported as it was only used with RunspaceConfiguration
PaulHigin
Oct 5, 2017
Contributor
But SaveAsConsoleFile() now no longer does anything useful. So I think this entire method should be removed.
| - /// Internal method used by RunspaceConfig for updating providers. | ||
| - /// </summary> | ||
| - /// <param name="providerConfig"></param> | ||
| - private ProviderInfo AddProvider(ProviderConfigurationEntry providerConfig) |
PaulHigin
Oct 4, 2017
Contributor
It looks like RemoveProvider on line 1523 should be removed too, since it is only used for RunspaceConfiguration.
| @@ -5070,9 +5069,6 @@ internal void SaveAsConsoleFile(string path) | ||
| { | ||
| throw PSTraceSource.NewArgumentException("path", ConsoleInfoErrorStrings.BadConsoleExtension); | ||
| } | ||
| - |
PaulHigin
Oct 4, 2017
Contributor
I don't understand why this was removed. It looks like the only purpose of this helper method is to write to file.
SteveL-MSFT
Oct 4, 2017
Owner
PSConsoleFile is not supported as it was only used with RunspaceConfiguration
PaulHigin
Oct 5, 2017
Contributor
But SaveAsConsoleFile() now no longer does anything useful. So I think this entire method should be removed.
| - throw PSTraceSource.NewArgumentNullException("runspaceConfiguration"); | ||
| - } | ||
| - | ||
| + InitialSessionState = InitialSessionState.CreateDefault2(); |
PaulHigin
Oct 5, 2017
Contributor
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.
SteveL-MSFT
Oct 9, 2017
Owner
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.
daxian-dbw
Oct 13, 2017
•
Member
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.
| + // All ISS-based configuration of the engine itself is done by AutomationEngine, | ||
| + // which calls InitialSessionState.Bind(). Anything that doesn't | ||
| + // require an active and open runspace should be done in ISS.Bind() | ||
| + _engine = new AutomationEngine(Host, InitialSessionState); |
PaulHigin
Oct 5, 2017
Contributor
I think we should add an assert here to ensure InitialSessionState is never null.
| if (host == null) | ||
| { | ||
| throw PSTraceSource.NewArgumentNullException("host"); | ||
| } | ||
| - rsConfig = runspaceConfiguration; |
PaulHigin
Oct 5, 2017
Contributor
_initialSessionState is null after this constructor runs. Is this Ok?
| - { | ||
| - result = RunspaceFactory.CreateRunspaceFromSessionStateNoClone(host, _initialSessionState); | ||
| - } | ||
| + result = RunspaceFactory.CreateRunspaceFromSessionStateNoClone(host, _initialSessionState); |
PaulHigin
Oct 5, 2017
Contributor
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.
| @@ -758,34 +45,4 @@ internal enum RunspaceConfigurationCategory | ||
| Formats, |
PaulHigin
Oct 5, 2017
Contributor
Can this file just be removed? It looks like it only contains code related to runspace configuration.
SteveL-MSFT
Oct 11, 2017
Owner
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
lzybkr
Oct 11, 2017
Member
You could rename - it's being used in Update-FormatData which is not snap-in related.
SteveL-MSFT
Oct 13, 2017
Owner
Moving enum to FormatAndTypeDataHelper.cs and moving that file to utils. Removing the last of the RunspaceConfiguration*.cs files
SteveL-MSFT
Oct 13, 2017
Owner
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.
SteveL-MSFT
modified the milestone:
build
Oct 11, 2017
SteveL-MSFT
added
Committee-Reviewed
and removed
Review - Committee
labels
Oct 12, 2017
|
@PowerShell/powershell-committee reviewed this and agreed on removal on RunspaceConfiguration code |
daxian-dbw
referenced this pull request
Oct 12, 2017
Closed
Hosted PS core in ASP.Net core The system cannot find the file specified #5084
| @@ -1749,7 +1468,7 @@ internal int ProviderCount | ||
| return count; | ||
| } | ||
| } // ProviderCount | ||
| - } // SessionStateInternal class | ||
| + } // SessionStateInternal class} |
| @@ -43,7 +43,7 @@ protected RunspaceBase(PSHost host) | ||
| { | ||
| throw PSTraceSource.NewArgumentNullException("host"); | ||
| } | ||
| - InitialSessionState = InitialSessionState.CreateDefault2(); | ||
| + InitialSessionState = InitialSessionState.CreateDefault(); |
PaulHigin
Oct 12, 2017
Contributor
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.
SteveL-MSFT
Oct 12, 2017
Owner
This is where I need some expertise to mimic the previous RunspaceConfiguration behavior. @lzybkr @daxian-dbw ?
lzybkr
Oct 12, 2017
Member
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)
| @@ -84,6 +84,7 @@ internal class RunspacePoolInternal | ||
| pool = new Stack<Runspace>(); | ||
| runspaceRequestQueue = new Queue<GetRunspaceAsyncResult>(); | ||
| ultimateRequestQueue = new Queue<GetRunspaceAsyncResult>(); | ||
| + _initialSessionState = InitialSessionState.CreateDefault(); |
PaulHigin
Oct 12, 2017
Contributor
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.
SteveL-MSFT
Oct 13, 2017
Owner
Based on Jason's test, CreateDefault() is the faster one while CreateDefault2() does more, I'll update the comments on those methods
lzybkr
Oct 13, 2017
Member
Note that it feels like something is terribly wrong with CreateDefault2, so that's investigating. It should be faster like Paul suggested.
| - } | ||
| - else | ||
| + // Special switch for debug mode | ||
| + if (args.Length > 0 && !String.IsNullOrEmpty(args[0]) && args[0].Equals("-isswait", StringComparison.OrdinalIgnoreCase)) | ||
| { |
lzybkr
Oct 12, 2017
Member
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.
SteveL-MSFT
Oct 13, 2017
Owner
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.
lzybkr
Oct 13, 2017
Member
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.
| - this.RunspaceConfiguration.Unbind(this); | ||
| - } | ||
| - | ||
| - EngineSessionState.RunspaceClosingNotification(); |
| @@ -391,11 +391,6 @@ internal void SetConsoleVariable() | ||
| { |
lzybkr
Oct 12, 2017
Member
Consider removing this whole function and the special variable now that console files went away.
| - try | ||
| - { | ||
| - providerBase.Stop(context); | ||
| - } |
lzybkr
Oct 12, 2017
Member
It's hard to be certain all of this code can be safely deleted, but this line is worrisome - it potentially calls third party code to clean up resources.
SteveL-MSFT
Oct 13, 2017
Owner
Best that I could tell, RemoveProvider() is only used for RunspaceConfiguration
lzybkr
Oct 13, 2017
Member
I think there is a bug in LocalRunspace.DoCloseHelper then - there is an early return in there, and if it always returns, there are multiple things we're not doing at shutdown, e.g. we're not firing the exiting event.
Bottom line - not hitting the code doesn't mean much w.r.t. RunspaceConfiguration, at least based on my review of the code and quick debugging of process exit.
SteveL-MSFT
Oct 13, 2017
Owner
I'll change the DoCloseHelper() method. Based on the comments, it's preventing stopping transcription until all the runspaces are closed, so I'll just use a flag to catch if there's any open runspaces and will continue with the rest of DoCloseHelper() to shutdown.
| - // Log the provider stopped event | ||
| - | ||
| - MshLog.LogProviderLifecycleEvent( | ||
| - this.ExecutionContext, |
lzybkr
Oct 12, 2017
Member
It's possible this event is used by forensic tools - as much as I'd like to get rid of it.
SteveL-MSFT
Oct 13, 2017
Owner
If we know that RemoveProvider is used outside of RunspaceConfig, I can put this back, but currently it doesn't seem to be the case.
| - CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); | ||
| - | ||
| - Collection<string> keys = new Collection<string>(); | ||
| - foreach (string key in Providers.Keys) |
lzybkr
Oct 12, 2017
Member
I'm not sure we should remove this method, but this extra loop is pointless - just copying the keys to a temp collection.
SteveL-MSFT
Oct 13, 2017
•
Owner
I wasn't sure about this method. I set a breakpoint in it and couldn't get it to hit within the if statement using runspace creation. It also seems that RemoveProvider() is only used by RunspaceConfiguration
daxian-dbw
Oct 13, 2017
Member
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.
| @@ -4218,9 +4218,6 @@ public void AddType(TypeData typeData) | ||
| Update(errors, typeData, false); | ||
| StandardMembersUpdated(); | ||
| - | ||
| - // Throw exception if there are any errors | ||
| - FormatAndTypeDataHelper.ThrowExceptionOnError("ErrorsUpdatingTypes", errors, RunspaceConfigurationCategory.Types); | ||
| } |
| @@ -4245,9 +4242,6 @@ public void RemoveType(string typeName) | ||
| Update(errors, typeData, true); | ||
| StandardMembersUpdated(); | ||
| - | ||
| - // Throw exception if there are any errors | ||
| - FormatAndTypeDataHelper.ThrowExceptionOnError("ErrorsUpdatingTypes", errors, RunspaceConfigurationCategory.Types); | ||
| } |
| @@ -67,72 +65,12 @@ public static Runspace CreateRunspace(PSHost host) | ||
| throw PSTraceSource.NewArgumentNullException("host"); | ||
| } | ||
| - return CreateRunspace(host, RunspaceConfiguration.Create()); | ||
| + return new LocalRunspace(host); | ||
| } |
lzybkr
Oct 12, 2017
Member
We should construct the InitialSessionState here and call the appropriate constructor.
As for using CreateDefault vs. CreateDefault2, the argument that CreateDefault2 is faster is apparently very wrong, I measure it as 8X slower:
#88 PS> 'CreateDefault','CreateDefault2' | %{ measure-command {
>> $iss = [InitialSessionState]::$_();
>> 1..100 | % { $ps = [powershell]::Create($iss).AddCommand('echo').AddArgument(1); $ps.Invoke(); $ps.Dispose() } } }
1.003s
8.247s
If I change the example to not load any commands, then they are more similar:
#89 PS> 'CreateDefault','CreateDefault2' | %{ measure-command {
$iss = [InitialSessionState]::$_();
1..100 | % { $ps = [powershell]::Create($iss).AddScript('1'); $ps.Invoke(); $ps.Dispose() } } }
1.209s
1.037s
SteveL-MSFT
Oct 13, 2017
Owner
On my MacBookPro, CreateDefault2() is 3x slower and on Windows it's 2.5x slower, but consistently slower to use CreateDefault2()
| - internal LocalRunspace(PSHost host, RunspaceConfiguration runspaceConfig) | ||
| - : base(host, runspaceConfig) | ||
| + internal LocalRunspace(PSHost host) | ||
| + : base(host) |
And the *PSSnapin lines. In reply to: 336302306 [](ancestors = 336302306) Refers to: src/System.Management.Automation/engine/InitialSessionState.cs:5572 in 6121d89. [](commit_id = 6121d89, deletion_comment = False) |
|
I believe all feedback has been addressed |
PaulHigin
approved these changes
Oct 13, 2017
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
requested changes
Oct 13, 2017
I'm now looking at ConnectionFactory.cs, but want to share my existing feedback early.
| @@ -133,18 +133,6 @@ public bool MoveNext() | ||
| } | ||
| - // Advance the state | ||
| - _currentState = SearchState.SearchingBuiltinScripts; |
daxian-dbw
Oct 13, 2017
Member
Is it safe to remove the enum number SearchState.SearchingBuiltinScripts? It doesn't seem to be needed anymore.
| /// </summary> | ||
| /// | ||
| internal bool IsSingleShell | ||
| { | ||
| get | ||
| { | ||
| - RunspaceConfigForSingleShell runSpace = RunspaceConfiguration as RunspaceConfigForSingleShell; | ||
| - return runSpace != null || InitialSessionState != null; | ||
| + return InitialSessionState != null; |
daxian-dbw
Oct 13, 2017
Member
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.
| set | ||
| { | ||
| - if (this.RunspaceConfiguration != null) | ||
| - throw new NotImplementedException("set_FormatDBManager()"); | ||
| _formatDBManager = value; |
daxian-dbw
Oct 13, 2017
Member
It looks to me we can remove the set method now, as it's only used for a RunspaceConfiguration scenario.
| - { | ||
| - consoleFileName = rcss.ConsoleInfo.Filename; | ||
| - } | ||
| - PSVariable v = new PSVariable(SpecialVariables.ConsoleFileName, |
daxian-dbw
Oct 13, 2017
Member
SpecialVariables.ConsoleFileName in SpecialVariables.cs can be removed now
| - CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); | ||
| - | ||
| - Collection<string> keys = new Collection<string>(); | ||
| - foreach (string key in Providers.Keys) |
lzybkr
Oct 12, 2017
Member
I'm not sure we should remove this method, but this extra loop is pointless - just copying the keys to a temp collection.
SteveL-MSFT
Oct 13, 2017
•
Owner
I wasn't sure about this method. I set a breakpoint in it and couldn't get it to hit within the if statement using runspace creation. It also seems that RemoveProvider() is only used by RunspaceConfiguration
daxian-dbw
Oct 13, 2017
Member
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.
| - internal void RemoveProvider( | ||
| - string providerName, | ||
| - bool force, | ||
| - CmdletProviderContext context) |
daxian-dbw
Oct 13, 2017
Member
Same question here. This method doesn't look like solely related to RunspaceConfiguration.
daxian-dbw
Oct 17, 2017
Member
These following two methods seem OK to be removed:
private void RemoveProvider(ProviderConfigurationEntry entry)
private string GetProviderName(ProviderConfigurationEntry entry)
| @@ -4221,7 +4221,7 @@ public void AddType(TypeData typeData) | ||
| // Throw exception if there are any errors | ||
| FormatAndTypeDataHelper.ThrowExceptionOnError("ErrorsUpdatingTypes", errors, RunspaceConfigurationCategory.Types); | ||
| - } | ||
| + } |
| - throw PSTraceSource.NewArgumentNullException("runspaceConfiguration"); | ||
| - } | ||
| - | ||
| + InitialSessionState = InitialSessionState.CreateDefault2(); |
PaulHigin
Oct 5, 2017
Contributor
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.
SteveL-MSFT
Oct 9, 2017
Owner
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.
daxian-dbw
Oct 13, 2017
•
Member
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.
| @@ -67,72 +65,12 @@ public static Runspace CreateRunspace(PSHost host) | ||
| throw PSTraceSource.NewArgumentNullException("host"); | ||
| } | ||
| - return CreateRunspace(host, RunspaceConfiguration.Create()); | ||
| + return new LocalRunspace(host, InitialSessionState.CreateDefault2()); |
daxian-dbw
Oct 13, 2017
Member
Same here, if we want to mimic the existing behavior, then we should use CreateDefault.
| } | ||
| } | ||
| PSHostUserInterface host = executionContext.EngineHostInterface.UI; | ||
| - if (host != null) | ||
| + if (host != null && stopTranscription) |
daxian-dbw
Oct 13, 2017
Member
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.
SteveL-MSFT
Oct 13, 2017
Owner
@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.
daxian-dbw
Oct 13, 2017
Member
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.
daxian-dbw
Oct 14, 2017
Member
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.
SteveL-MSFT
Oct 14, 2017
Owner
I'll change it so if there's no open runspaces left, transcription is stopped and AmsiUtils.Uninitialize() is called.
| this.host = host; | ||
| pool = new Stack<Runspace>(); | ||
| runspaceRequestQueue = new Queue<GetRunspaceAsyncResult>(); | ||
| ultimateRequestQueue = new Queue<GetRunspaceAsyncResult>(); | ||
| + _initialSessionState = InitialSessionState.CreateDefault2(); |
daxian-dbw
Oct 13, 2017
Member
Same here. If we want to mimic RunspaceConfiguration, then CreateDefault() should be used.
| @@ -246,9 +246,7 @@ internal string GetDefaultShellSearchPath() | ||
| /// <returns>true if supported,false otherwise.</returns> | ||
| internal bool AreSnapInsSupported() |
daxian-dbw
Oct 13, 2017
Member
I think this method should be removed, and update the two call sites in HelpProviderWithFullCache.cs:
if (!this.CacheFullyLoaded || AreSnapInsSupported()) ==> if (!this.CacheFullyLoaded)
| - ConsoleHost.DefaultInitialSessionState = InitialSessionState.CreateDefault2(); | ||
| - configuration = null; | ||
| - } | ||
| - else if (args.Length > 0 && !String.IsNullOrEmpty(args[0]) && args[0].Equals("-isswait", StringComparison.OrdinalIgnoreCase)) |
daxian-dbw
Oct 16, 2017
Member
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.
lzybkr
Oct 16, 2017
Member
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.
| } | ||
| +#else | ||
| + ConsoleHost.DefaultInitialSessionState = InitialSessionState.CreateDefault2(); | ||
| +#endif |
daxian-dbw
Oct 17, 2017
Member
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();
| { | ||
| host.StopAllTranscribing(); | ||
| + AmsiUtils.Uninitialize(); |
daxian-dbw
Oct 17, 2017
•
Member
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 is also a comment at #4942 (comment). |
daxian-dbw
approved these changes
Oct 17, 2017
LGTM. Thanks @SteveL-MSFT for getting this done!
daxian-dbw
dismissed
lzybkr’s
stale review
Oct 17, 2017
New commits have been pushed to address comments.
SteveL-MSFT
added some commits
Sep 28, 2017
|
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. |


SteveL-MSFT commentedSep 28, 2017
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.