removed RunspaceConfiguration support #4942

Merged
merged 8 commits into from Oct 18, 2017

Conversation

Projects
None yet
4 participants
Owner

SteveL-MSFT commented Sep 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.

@SteveL-MSFT SteveL-MSFT requested review from daxian-dbw and lzybkr Sep 28, 2017

Member

daxian-dbw commented Sep 28, 2017

@SteveL-MSFT powershell.Invoke() (maybe some other part of the powershell class) goes through RunspaceConfiguration, for example the following script:

$ps = [powershell]::Create()
$ps.AddScript("gcm")
$ps.Invoke()

Did you change it to not depend on RunspaceConfiguration?

Owner

SteveL-MSFT commented Sep 28, 2017

@daxian-dbw yes, I changed it to use InitialSessionState

Member

daxian-dbw commented Sep 29, 2017

@SteveL-MSFT Awesome! Can you please point me to the part of changes that related to powershell.invoke()?

Owner

SteveL-MSFT commented Sep 29, 2017

@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 SteveL-MSFT referenced this pull request Oct 4, 2017

Merged

Clean up console code #4995

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(
@PaulHigin

PaulHigin Oct 4, 2017

Contributor

Why was this error processing removed?

@SteveL-MSFT

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

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 Throw

In reply to: 142809956 [](ancestors = 142809956)

@SteveL-MSFT

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

SteveL-MSFT Oct 13, 2017

Owner

I tried this (fixing the @" "@ here string) and it doesn't throw on Beta.8.

@lzybkr

lzybkr Oct 13, 2017

Member

It does for me, Windows PowerShell and Beta 8 on Windows.

@SteveL-MSFT

SteveL-MSFT Oct 17, 2017

Owner

repro'ing for me now, will add test

- 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
@PaulHigin

PaulHigin Oct 4, 2017

Contributor

Is this TODO comment valid anymore?

@SteveL-MSFT

SteveL-MSFT Oct 4, 2017

Owner

I think the commend can be removed

- configuration = null;
- }
-#else
+ if (args.Length > 0 && !String.IsNullOrEmpty(args[0]) && args[0].Equals("-iss", StringComparison.OrdinalIgnoreCase))
@PaulHigin

PaulHigin Oct 4, 2017

Contributor

We do the same thing in the else block so we don't need this condition.

@SteveL-MSFT

SteveL-MSFT Oct 4, 2017

Owner

Yes, will move it out

set
{
- if (this.RunspaceConfiguration != null)
- throw new NotImplementedException("set_TypeTable()");
_typeTable = value;
_typeTableWeakReference = value != null ? new WeakReference<TypeTable>(value) : null;
@PaulHigin

PaulHigin Oct 4, 2017

Contributor

Nitpick. I think this is easier to read if the condition expression is in parentheses: ... = (value != null) ? ...

@SteveL-MSFT

SteveL-MSFT Oct 4, 2017

Owner

I can fix that

- /// RunspaceConfiguration information
- /// </param>
- internal ExecutionContext(AutomationEngine engine, PSHost hostInterface, RunspaceConfiguration runspaceConfiguration)
+ internal ExecutionContext(AutomationEngine engine, PSHost hostInterface)
@PaulHigin

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.

@SteveL-MSFT

SteveL-MSFT Oct 4, 2017

Owner

I'll check; if this isn't used anymore I'll remove it

@@ -5070,9 +5069,6 @@ internal void SaveAsConsoleFile(string path)
{
throw PSTraceSource.NewArgumentException("path", ConsoleInfoErrorStrings.BadConsoleExtension);
}
-
@PaulHigin

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

SteveL-MSFT Oct 4, 2017

Owner

PSConsoleFile is not supported as it was only used with RunspaceConfiguration

@PaulHigin

PaulHigin Oct 5, 2017

Contributor

But SaveAsConsoleFile() now no longer does anything useful. So I think this entire method should be removed.

@SteveL-MSFT

SteveL-MSFT Oct 6, 2017

Owner

Yes, SaveAsConsoleFile() should be removed

- /// Internal method used by RunspaceConfig for updating providers.
- /// </summary>
- /// <param name="providerConfig"></param>
- private ProviderInfo AddProvider(ProviderConfigurationEntry providerConfig)
@PaulHigin

PaulHigin Oct 4, 2017

Contributor

It looks like RemoveProvider on line 1523 should be removed too, since it is only used for RunspaceConfiguration.

@SteveL-MSFT

SteveL-MSFT Oct 4, 2017

Owner

Will remove

@SteveL-MSFT

SteveL-MSFT Oct 13, 2017

Owner

based on our code coverage that code has never been hit

@@ -5070,9 +5069,6 @@ internal void SaveAsConsoleFile(string path)
{
throw PSTraceSource.NewArgumentException("path", ConsoleInfoErrorStrings.BadConsoleExtension);
}
-
@PaulHigin

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

SteveL-MSFT Oct 4, 2017

Owner

PSConsoleFile is not supported as it was only used with RunspaceConfiguration

@PaulHigin

PaulHigin Oct 5, 2017

Contributor

But SaveAsConsoleFile() now no longer does anything useful. So I think this entire method should be removed.

@SteveL-MSFT

SteveL-MSFT Oct 6, 2017

Owner

Yes, SaveAsConsoleFile() should be removed

- throw PSTraceSource.NewArgumentNullException("runspaceConfiguration");
- }
-
+ InitialSessionState = InitialSessionState.CreateDefault2();
@PaulHigin

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

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

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

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

PaulHigin Oct 5, 2017

Contributor

_initialSessionState is null after this constructor runs. Is this Ok?

@SteveL-MSFT

SteveL-MSFT Oct 11, 2017

Owner

I'll create a default one

- {
- result = RunspaceFactory.CreateRunspaceFromSessionStateNoClone(host, _initialSessionState);
- }
+ result = RunspaceFactory.CreateRunspaceFromSessionStateNoClone(host, _initialSessionState);
@PaulHigin

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

PaulHigin Oct 5, 2017

Contributor

Can this file just be removed? It looks like it only contains code related to runspace configuration.

@SteveL-MSFT

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

lzybkr Oct 11, 2017

Member

You could rename - it's being used in Update-FormatData which is not snap-in related.

@SteveL-MSFT

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

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 SteveL-MSFT modified the milestone: build Oct 11, 2017

Owner

SteveL-MSFT commented Oct 12, 2017

@PowerShell/powershell-committee reviewed this and agreed on removal on RunspaceConfiguration code

@@ -1749,7 +1468,7 @@ internal int ProviderCount
return count;
}
} // ProviderCount
- } // SessionStateInternal class
+ } // SessionStateInternal class}
@PaulHigin

PaulHigin Oct 12, 2017

Contributor

This looks strange. Can you remove the bracket from the comment?

@SteveL-MSFT

SteveL-MSFT Oct 12, 2017

Owner

Yes, that was probably just a mistake

@@ -43,7 +43,7 @@ protected RunspaceBase(PSHost host)
{
throw PSTraceSource.NewArgumentNullException("host");
}
- InitialSessionState = InitialSessionState.CreateDefault2();
+ InitialSessionState = InitialSessionState.CreateDefault();
@PaulHigin

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

SteveL-MSFT Oct 12, 2017

Owner

This is where I need some expertise to mimic the previous RunspaceConfiguration behavior. @lzybkr @daxian-dbw ?

@lzybkr

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

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

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

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.

@SteveL-MSFT

SteveL-MSFT Oct 13, 2017

Owner

I think that should be a separate issue. #5104

- }
- else
+ // Special switch for debug mode
+ if (args.Length > 0 && !String.IsNullOrEmpty(args[0]) && args[0].Equals("-isswait", StringComparison.OrdinalIgnoreCase))
{
@lzybkr

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

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

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.

@SteveL-MSFT

SteveL-MSFT Oct 13, 2017

Owner

Will remove

- this.RunspaceConfiguration.Unbind(this);
- }
-
- EngineSessionState.RunspaceClosingNotification();
@lzybkr

lzybkr Oct 12, 2017

Member

Why is this line deleted?

@@ -391,11 +391,6 @@ internal void SetConsoleVariable()
{
@lzybkr

lzybkr Oct 12, 2017

Member

Consider removing this whole function and the special variable now that console files went away.

@SteveL-MSFT

SteveL-MSFT Oct 13, 2017

Owner

will remove

- try
- {
- providerBase.Stop(context);
- }
@lzybkr

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

SteveL-MSFT Oct 13, 2017

Owner

Best that I could tell, RemoveProvider() is only used for RunspaceConfiguration

@lzybkr

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

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

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

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

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

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

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);
}
@lzybkr

lzybkr Oct 12, 2017

Member

I think this is still needed.

@SteveL-MSFT

SteveL-MSFT Oct 13, 2017

Owner

Will put back

@@ -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);
}
@lzybkr

lzybkr Oct 12, 2017

Member

I think this is still needed.

@SteveL-MSFT

SteveL-MSFT Oct 13, 2017

Owner

Will put back

@@ -67,72 +65,12 @@ public static Runspace CreateRunspace(PSHost host)
throw PSTraceSource.NewArgumentNullException("host");
}
- return CreateRunspace(host, RunspaceConfiguration.Create());
+ return new LocalRunspace(host);
}
@lzybkr

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

SteveL-MSFT Oct 13, 2017

Owner

will update

@SteveL-MSFT

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)
@lzybkr

lzybkr Oct 12, 2017

Member

Does this api make sense anymore?

@SteveL-MSFT

SteveL-MSFT Oct 13, 2017

Owner

will remove due to change in ConnectionFactory.cs

Member

lzybkr commented Oct 12, 2017

            {"Get-PSSnapin",                      new SessionStateCmdletEntry("Get-PSSnapin", typeof(GetPSSnapinCommand), helpFile) },

You can delete this line.


Refers to: src/System.Management.Automation/engine/InitialSessionState.cs:5572 in 6121d89. [](commit_id = 6121d89, deletion_comment = False)

Member

lzybkr commented Oct 12, 2017

            {"Get-PSSnapin",                      new SessionStateCmdletEntry("Get-PSSnapin", typeof(GetPSSnapinCommand), helpFile) },

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)

Owner

SteveL-MSFT commented Oct 13, 2017

I believe all feedback has been addressed

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.

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

daxian-dbw Oct 13, 2017

Member

Is it safe to remove the enum number SearchState.SearchingBuiltinScripts? It doesn't seem to be needed anymore.

@SteveL-MSFT

SteveL-MSFT Oct 14, 2017

Owner

Yes, looks safe to remove as it's no longer being used

/// </summary>
///
internal bool IsSingleShell
{
get
{
- RunspaceConfigForSingleShell runSpace = RunspaceConfiguration as RunspaceConfigForSingleShell;
- return runSpace != null || InitialSessionState != null;
+ return InitialSessionState != null;
@daxian-dbw

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.

@SteveL-MSFT

SteveL-MSFT Oct 14, 2017

Owner

yup, will clean up

set
{
- if (this.RunspaceConfiguration != null)
- throw new NotImplementedException("set_FormatDBManager()");
_formatDBManager = value;
@daxian-dbw

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.

@SteveL-MSFT

SteveL-MSFT Oct 14, 2017

Owner

will remove

@SteveL-MSFT

SteveL-MSFT Oct 14, 2017

Owner

looks like InitialSessionState.cs:3582 uses it

- {
- consoleFileName = rcss.ConsoleInfo.Filename;
- }
- PSVariable v = new PSVariable(SpecialVariables.ConsoleFileName,
@daxian-dbw

daxian-dbw Oct 13, 2017

Member

SpecialVariables.ConsoleFileName in SpecialVariables.cs can be removed now

@SteveL-MSFT

SteveL-MSFT Oct 14, 2017

Owner

will remove

- CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);
-
- Collection<string> keys = new Collection<string>();
- foreach (string key in Providers.Keys)
@lzybkr

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

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

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

daxian-dbw Oct 13, 2017

Member

Same question here. This method doesn't look like solely related to RunspaceConfiguration.

@SteveL-MSFT

SteveL-MSFT Oct 14, 2017

Owner

Putting back

@daxian-dbw

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

SteveL-MSFT Oct 17, 2017

Owner

Will remove.

@@ -4221,7 +4221,7 @@ public void AddType(TypeData typeData)
// Throw exception if there are any errors
FormatAndTypeDataHelper.ThrowExceptionOnError("ErrorsUpdatingTypes", errors, RunspaceConfigurationCategory.Types);
- }
+ }
@daxian-dbw

daxian-dbw Oct 13, 2017

Member

This change seems unnecessary. The extra space should be removed.

- throw PSTraceSource.NewArgumentNullException("runspaceConfiguration");
- }
-
+ InitialSessionState = InitialSessionState.CreateDefault2();
@PaulHigin

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

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

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.

Done through all changes.

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

daxian-dbw Oct 13, 2017

Member

Same here, if we want to mimic the existing behavior, then we should use CreateDefault.

@SteveL-MSFT

SteveL-MSFT Oct 14, 2017

Owner

will change

}
}
PSHostUserInterface host = executionContext.EngineHostInterface.UI;
- if (host != null)
+ if (host != null && stopTranscription)
@daxian-dbw

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

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

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

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

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

daxian-dbw Oct 13, 2017

Member

Same here. If we want to mimic RunspaceConfiguration, then CreateDefault() should be used.

@SteveL-MSFT

SteveL-MSFT Oct 14, 2017

Owner

will change

@@ -246,9 +246,7 @@ internal string GetDefaultShellSearchPath()
/// <returns>true if supported,false otherwise.</returns>
internal bool AreSnapInsSupported()
@daxian-dbw

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)

@SteveL-MSFT

SteveL-MSFT Oct 14, 2017

Owner

will update and remove no longer relevant comment

- ConsoleHost.DefaultInitialSessionState = InitialSessionState.CreateDefault2();
- configuration = null;
- }
- else if (args.Length > 0 && !String.IsNullOrEmpty(args[0]) && args[0].Equals("-isswait", StringComparison.OrdinalIgnoreCase))
@daxian-dbw

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

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.

@SteveL-MSFT

SteveL-MSFT Oct 16, 2017

Owner

I'll put in the updated version Jason is suggesting

}
+#else
+ ConsoleHost.DefaultInitialSessionState = InitialSessionState.CreateDefault2();
+#endif
@daxian-dbw

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();
@SteveL-MSFT

SteveL-MSFT Oct 17, 2017

Owner

sounds good

{
host.StopAllTranscribing();
+ AmsiUtils.Uninitialize();
@daxian-dbw

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 StopAllTranscribing if host != null, and then call AmsiUtils.Uninitialize().
@SteveL-MSFT

SteveL-MSFT Oct 17, 2017

Owner

will revert previous change

Member

daxian-dbw commented Oct 17, 2017

There is also a comment at #4942 (comment).

LGTM. Thanks @SteveL-MSFT for getting this done!

New commits have been pushed to address comments.

SteveL-MSFT added some commits Sep 28, 2017

[feature]
removed RunspaceConfiguration
[feature]
fix test to use Source property as PSSnapin is no longer filled in without RunspaceConfig
[feature]
address PR feedback
[feature]
address PR feedback
[feature]
refactor some code
[feature]
address Dongbo's feedback
[feature]
added back -isswait debug support
added test for Update-FormatData
[feature]
address Dongbo's feedback
marked update-format invalid test as pending
Owner

SteveL-MSFT commented Oct 18, 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.

@daxian-dbw daxian-dbw merged commit 6177d28 into PowerShell:master Oct 18, 2017

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
license/cla All CLA requirements met.
Details

powercode pushed a commit to powercode/PowerShell that referenced this pull request Oct 19, 2017

removed RunspaceConfiguration support (#4942)
For PSCore 6, we are only supporting InitialSessionState. The RunspaceConfiguration APIs were 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.

@SteveL-MSFT SteveL-MSFT deleted the SteveL-MSFT:consoleinfo branch Nov 12, 2017

Bhaal22 added a commit to Bhaal22/PowerShell that referenced this pull request Nov 28, 2017

Runspaceconfiguration still mentionned in RunspacePoolInternal ctor A…
…PI documentation

Removed 2 obsolete test files

 #4942

Bhaal22 added a commit to Bhaal22/PowerShell that referenced this pull request Nov 29, 2017

Runspaceconfiguration still mentionned in RunspacePoolInternal ctor A…
…PI documentation

Updated the 2 unit tests accordingly with Runspaceconfiguration removal

 #4942
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment