-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fix blocking wait when starting file associated with a Windows application #13750
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
Conversation
|
@SteveL-MSFT I think we should simply revert a change in line 557 As for test, you could see last test in Invoke-Item.Tests,ps1 file: |
|
@iSazonov the problem is if anyone updates the code and uses As for the test, it appears the hang only occurs if the associated process explicitly supports elevation like mmc.exe. I can add a test that runs if |
My thoughts is that switching to mmc.exe is temporary and we should follow diskmgmt.msc. Otherwise it will very tricky code - input is diskmgmt.msc but result is for mmc.exe. |
|
@iSazonov but |
|
If we remove IsWindowsApplication we remove _isWindowsApplication and this resolves our discussion (til we will want to make IsWindowsApplication public :-) ) |
| _startPosition = new Host.Coordinates(); | ||
|
|
||
| CalculateIORedirection(out redirectOutput, out redirectError, out redirectInput); | ||
| bool isWindowsApplication = IsWindowsApplication(this.Path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These names are so similar that it can be confused. Can we keep the old name for the method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old name with the Check makes it slightly harder to understand reading the code as it's not as clear what true/false means with Check vs Is. The alternative is to have the local variable be isConsoleApplication to differentiate I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use bool windowsApplication without Bulgarian prefix.
If no I agreed with isWindowsApplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this code currently is only used in one place, I think the casing diff is ok and prefer the is making it a bit more readable
|
As unrelated notice. The code fallback to default shell (cmd.exe/bash) to invoke an item. But what if we assign PowerShell as default shell? Infinite cycle? |
|
@iSazonov can you point me to what code you are referring to? |
|
In the context - line 488. If UseShellExecute is true we call PowerShell again? |
|
@iSazonov that line with UseShellExecute only starts a new process if the previous attempt fails because it's not an executable and isn't associated with an executable so it tries to let the Shell try to start it. I don't see the problem. |
|
I mean the code PowerShell/src/System.Management.Automation/engine/NativeCommandProcessor.cs Lines 478 to 490 in f2a3716
If PowerShell is default shell the code will run PowerShell again and again. |
|
@iSazonov ok, now I see what you mean. However, on my macBook I can see that Process.Start() doesn't start a new shell to run the exe. |
|
I'd expect the cycle with:
In line 534 we will have UseShellExecute = true and run PowerShell again. |
|
@iSazonov perhaps you can open a new issue to discuss that specific concern, I don't see additional pwsh processes, however |
|
@SteveL-MSFT I looked at the UseShellExecute implementation. It does not use a call to default shell. On Windows it uses ShellExecuteEx P/Invoke, on Unix it uses x-bit. So the cycle would be only if PowerShell associated with the extension or file. |
|
🎉 Handy links: |
|
🎉 Handy links: |
|
Is this in 7.1 stable? I don't see a revert to this commit in the diff log between 7.1 and 7.1-rc2, but it's re-incorporated in 7.2 preview 1. |
|
It was included in v7.2.0-preview.1. You can check that 7.1 works well in the scenario. |
So... both versions have it? |
|
Yes, both. |
PR Summary
Change #13481 modified some logic on how console apps are detected. The problem in this situation is:
diskmgmt.msc_isWindowsApplication = falsemmc.exe_isWindowsApplicationto determine if we block waiting for exe to finish, since this value was cached and not updated on step 5, it treats as console exe and waitsFix is to change
CheckIfConsoleApplication()to be non-static so that the second time it's called it updates_isWindowsApplicationto point to the new exe and not the previous file.Tested manually. Since CI won't have a Windows app associated with a file, can't create a test case.
PR Context
Fix #13744
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.