Repository navigation
Closed
Labels
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime
Description
Steps to reproduce
try { } finally {
Write-Host Press ctrl c now
Start-Sleep 5
Write-Host You`'ll never see this one
}Evaluate the above script and press CTRL + C after the message is displayed.
Expected behavior
The entire finally block to complete.
Actual behavior
The finally block is cancelled when CTRL + C is pressed.
Environment data
Name Value
---- -----
PSVersion 7.0.0-preview.3
PSEdition Core
GitCommitId 7.0.0-preview.3
OS Microsoft Windows 10.0.18362
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
This also occurs on Windows PowerShell 5.1
Notes
If CTRL + C is pressed in the try block, additional key presses in the finally block will be correctly ignored. e.g.
try {
Write-Host Press ctrl c now
Start-Sleep 5
} finally {
Write-Host Try pressing it a bunch, won`'t do anything
Start-Sleep 5
Write-Host You`'ll actually see this one
}Reacted by Michael Klement
Reacted by Rain Sallow (/u/ta11ow)
Metadata
Metadata
Assignees
Labels
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime
Activity
[-]Finally clause can be [/-][+]Finally clause can be canceled with CTRL + C[/+]vexx32 commentedon Aug 28, 2019
Steve Lee (@SteveL-MSFT) Dongbo Wang (@daxian-dbw) this is... fairly serious, no? Being able to cancel a
finallyblock seems super not a good thing. 😦SeeminglyScience commentedon Aug 28, 2019
Looks like there's no real system to handle "delaying" stops.
The example in the notes works mostly by accident. In
ConsoleHost,^cspins up a thread that handles stops the current pipeline and waits for it to finish. In that handler, if that thread already exists it just returns early. So the notes example only works becauseConsoleHostthinks it's a duplicate stop request.A possible way to fix this would be to:
LocalPipelinecalled_areStopsDisabledLocalPipelinecalled_wasStopReceivedWhileDisabledwith a better nameLocalPipeline.CoreStopto check if_areStopsDisabledand to instead set_wasStopReceivedWhileDisablediftruefinallyblock to setLocalPipeline._areStopsDisabledbefore the body, and to throwPipelineStoppedExceptionafter the body if_wasStopReceivedWhileDisabledistruetry/finallyblocksiSazonov commentedon Aug 29, 2019
I guess it is not issue for background scripts like task scheduled.
For interactive session it could not big issue too - users press Ctrl-C most often when the script freezes and it can freezes in
finallyblock too.BrucePay commentedon Aug 29, 2019
I pretty much agree with Ilya (@iSazonov) - I don't think it's really a big issue. Once you hit ctrl-C, your shell is in an inconsistent state. Because that's how interactive shells work. If you're running a batch script/task or whatever, no one is hitting ctrl-C because - well - it's not interactive. The ctrl-C implementation in PowerShell is a pretty controlled compared to the first implementation (which simply terminated the thread.)
But if one was to change anything, there is a single value that represents the fact that the shell is stopping. Just save that value away in the finally clause then restore once finally is done. But wait - what if the user hit's stop again!?! That usually means that they really want it to stop. So the finalizer is interrupted. Well - that's what the user wanted. I don't have a problem with that.
vexx32 commentedon Aug 29, 2019
From a user perspective, that might make sense.
From a module author's perspective, that stance could be really dangerous. Sure, it might be what the user wants, but usually the things you put in a
finallyblock are pretty important. Cancelling afinallyblock can lead to corrupted data, memory leaks (objects can't be disposed properly), among a host of other problems.This should be fixed.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.