Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Only stop transcription when all runspaces are closed#3896

Merged
TravisEz13 merged 1 commit into
PowerShell:masterPowerShell/PowerShell:masterfrom
chunqingchen:bugfix1chunqingchen/PowerShell:bugfix1Copy head branch name to clipboard
Jun 13, 2017
Merged

Only stop transcription when all runspaces are closed#3896
TravisEz13 merged 1 commit into
PowerShell:masterPowerShell/PowerShell:masterfrom
chunqingchen:bugfix1chunqingchen/PowerShell:bugfix1Copy head branch name to clipboard

Conversation

@chunqingchen

@chunqingchen chunqingchen commented May 31, 2017

Copy link
Copy Markdown
Contributor

Fix issue #2334

Summary of the issue:

If user create any runspace within transcription and later close the runspace within the transcription, transcription get closed

Root cause of the issue:

When any runspace get closed, StopAllTranscribing() get called and the transcription get closed
Fix:

Check and make sure the we are closing the last runspace to stop transcription. otherwise user still need to explicitly call stop-transcript to close the transcription.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was confused by the code and the comment as I misread the comment initially. I think you should change the comment to avoid a double negative.

We should close transcripting only if we are running in default runspace

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

resolved

@chunqingchen

Copy link
Copy Markdown
Contributor Author

@SteveL-MSFT your comment is resolved.

@adityapatwardhan

Copy link
Copy Markdown
Member

I tried fixing this in Windows Powershell 5.1, but it broke with the following repro. Powershell crashes. Try running the following with a debugger attached.

powershell.exe -c "start-transcript"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We need a test case to cover the implicit closing of transcription

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

resolved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is tricky because DefaultRunspace is a thread static property and so there can be multiple DefaultRunspaces for multiple threads. It is really hard to know when all runspaces are closed. We do now keep a list of all (non-disposed) local runspaces. See Connection.cs https://github.com/PowerShell/PowerShell/blob/master/src/System.Management.Automation/engine/hostifaces/Connection.cs#L799
You could search through this list and if there is only one runspace left in the "open" state (meaning this is the last runspace) then do the stop transcribing.
This list only shows runspaces that have not yet been disposed. But a runspace can be non-open and still be in the list if it was not disposed, so you need to check the state of each runspace.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also I just realized that the "AmsiUtils.Uninitialize()" call should be done at the last runspace being closed as well. Can you please move that call into this logic too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

resolved.

@chunqingchen chunqingchen force-pushed the bugfix1 branch 2 times, most recently from 07358e3 to 44aee25 Compare June 6, 2017 23:40
@chunqingchen

Copy link
Copy Markdown
Contributor Author

@adityapatwardhan I tried your repro and powershell isn't crashing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Isn't this exactly the same as above?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

whoops~ ! deleted.

@chunqingchen

Copy link
Copy Markdown
Contributor Author

@PaulHigin @SteveL-MSFT your comments are resolved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AmsiUtils.Uninitialize() is still being called at line 930 below. Please remove that call so that uninitialize only happens when the last runspace closes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

resolved

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add new line at the end of the file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

resolved

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This problem is still in the file the image at the end of the review indicates there is not trailing newline.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

On windows, this will start the inbox Powershell, not v6.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Even on Linux, it will default to the installed one and not the running one. See https://github.com/PowerShell/PowerShell/blob/master/test/powershell/Host/ConsoleHost.Tests.ps1#L12

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Even on Linux, it will default to the installed one and not the running one. See https://github.com/PowerShell/PowerShell/blob/master/test/powershell/Host/ConsoleHost.Tests.ps1#L12

@chunqingchen chunqingchen force-pushed the bugfix1 branch 3 times, most recently from 80aac09 to 771e55a Compare June 8, 2017 00:11
@chunqingchen

Copy link
Copy Markdown
Contributor Author

@PaulHigin @SteveL-MSFT @adityapatwardhan your comments are resolved.

@adityapatwardhan adityapatwardhan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

After the newline at the end of the file is fixed.

@PaulHigin PaulHigin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@chunqingchen

Copy link
Copy Markdown
Contributor Author

@TravisEz13 Hi Travis, please merge the pr

@chunqingchen chunqingchen changed the title Fix the issue that Transcription for the host stops when any runspace… Fix the issue that PS only stops transcription when all runspaces are closed Jun 13, 2017
@TravisEz13 TravisEz13 changed the title Fix the issue that PS only stops transcription when all runspaces are closed Only stop transcription when all runspaces are closed Jun 13, 2017
@TravisEz13 TravisEz13 merged commit 65f96e0 into PowerShell:master Jun 13, 2017
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.

6 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.