8000 Only stop transcription when all runspaces are closed by chunqingchen · Pull Request #3896 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Only stop transcription when all runspaces are closed #3896

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 1 commit into from
Jun 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -863,12 +863,24 @@ private void DoCloseHelper()
}

if ((hostRunspace == null) || (this == hostRunspace))
{
{
// We should close transcripting only if we are closing the last opened runspace.
foreach (Runspace runspace in RunspaceList)
{
// At this stage, the last opened runspace should be at closing state.
if (runspace.RunspaceStateInfo.State == RunspaceState.Opened)
{
return;
}
}

PSHostUserInterface host = executionContext.EngineHostInterface.UI;
if (host != null)
{
host.StopAllTranscribing();
}

AmsiUtils.Uninitialize();
Copy link
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
Contributor Author

Choose a reason for hiding this comment

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

resolved

}
}

Expand Down Expand Up @@ -913,10 +925,7 @@ private void DoCloseHelper()

//Log engine lifecycle event.
MshLog.LogEngineLifecycleEvent(_engine.Context, EngineState.Stopped);

// Uninitialize the AMSI scan interface
AmsiUtils.Uninitialize();


//All pipelines have been canceled. Close the runspace.
_engine = null;
_commandFactory = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,34 @@ Describe "Start-Transcript, Stop-Transcript tests" -tags "CI" {
$expectedError = "CannotStartTranscription,Microsoft.PowerShell.Commands.StartTranscriptCommand"
ValidateTranscription -scriptToExecute $script -outputFilePath $null -expectedError $expectedError
}
It "Transcription should remain active if other runspace in the host get closed" {
try{
$ps = [powershell]::Create()
$ps.addscript("Start-Transcript -path $transcriptFilePath").Invoke()
$ps.addscript('$rs = [system.management.automation.runspaces.runspacefactory]::CreateRunspace()').Invoke()
$ps.addscript('$rs.open()').Invoke()
$ps.addscript('$rs.Dispose()').Invoke()
$ps.addscript('Write-Host "After Dispose"').Invoke()
$ps.addscript("Stop-Transcript").Invoke()
} finally {
if ($ps -ne $null) {
$ps.Dispose()
}
}


Test-Path $transcriptFilePath | Should be $true
$transcriptFilePath | Should contain "After Dispose"
}

It "Transcription should be closed if the only runspace gets closed" {
$powerShellPath = [System.Diagnostics.Process]::GetCurrentProcess().Path
$powerShellCommand = $powerShellPath + ' "start-transcript $transcriptFilePath; Write-Host ''Before Dispose'';"'
Invoke-Expression $powerShellCommand

Test-Path $transcriptFilePath | Should be $true
$transcriptFilePath | Should contain "Before Dispose"
$transcriptFilePath | Should contain "Windows PowerShell transcript end"
}
Copy link
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
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
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.


}
0