Skip to content

Refactor and clean up based on the dependency management changes #194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 27, 2019

Conversation

daxian-dbw
Copy link
Contributor

@daxian-dbw daxian-dbw commented Apr 25, 2019

Refactor and clean up the code base based on the dependency management changes.

@daxian-dbw
Copy link
Contributor Author

@SatishRanjan and @TylerLeonhardt Can you please take a look at this PR?
This PR does some minor refactoring to reduce redundancy, and change the line ending in Utils.cs.

iss.ExecutionPolicy = Microsoft.PowerShell.ExecutionPolicy.Unrestricted;
}

s_initialSessionState = iss;
Copy link
Contributor

@SatishRanjan SatishRanjan Apr 26, 2019

Choose a reason for hiding this comment

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

Is reusing same instance of InitialSessionState not going to cause issue especially when PowerShell instance pool size is greater than 1, say for example if an instance of PowerShell goes wrong then during Dispose associated session will be disposed as well which will cause other PowerShell instance not function correctly? Or even sharing same session state object across instance of PowerShell object will cause erroneous behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm glad you asked this question!

A cloned copy of the passed in initialsessionstate will be actually used for the Runspace creation, see https://github.com/PowerShell/PowerShell/blob/master/src/System.Management.Automation/engine/hostifaces/ConnectionBase.cs#L78
So it's safe to reuse the same initialsessionstate to create multiple Runspaces.

@daxian-dbw daxian-dbw merged commit 61aabba into Azure:dev Apr 27, 2019
@daxian-dbw daxian-dbw deleted the refactor branch April 27, 2019 03:08
daxian-dbw added a commit to daxian-dbw/azure-functions-powershell-worker that referenced this pull request May 7, 2019
…re#194)

Fix no runspace available

Fix regression: create the first PowerShellManager in FunctionLoad, but delay the init

Update comments

Integrate all changes together

Clear the outputbinding hashtable for the runspace after get the results

Update tests and build scripts

Create constant functions so it's more secure

Alter the to-be-deployed PS function name to avoid conflicts with built-in functions

Use PowerShell API instead of 'InvokeScript' as the former is way faster

Bring back old code to clean global variables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants