-
Notifications
You must be signed in to change notification settings - Fork 560
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
Windows compiler invocation opens multiple console windows #514
Comments
@Systemcluster Are you using PowerShell? Do you mind giving your builds a shot through Command Prompt (ensuring that sccache is not already running)? I remember reading somewhere that PowerShell does not like edit 2: We may be able to justify removing |
@tangmi I was using PowerShell, but I'm seeing the same behavior with CMD. Same with |
@tangmi I tried around a bit with some more start parameters, and after some experimentation, I decided to perform some logging with some As far as I can tell (the sccache source is not the easiest to permeate) the popups appear inside |
Happens on a vanilla win7 cmd console also. |
Happens also on windows 8 in msys2's mintty. |
And win10 Sent with GitHawk |
it's a huge problem when running in Visual Studio Code + Rust Analyzer. Rust Analyzer invokes i believe we can not afford DETACHED_PROCESS anymore:
https://docs.microsoft.com/en-us/windows/win32/procthread/process-creation-flags |
For those who whant to change this behavior without recompilation: Don't forget to turn off sccache server beforehand (sccache.exe --stop-server). If interested, bytes 08060008 correspond to CREATE_NO_WINDOW(0x8000000) | CREATE_UNICODE_ENVIRONMENT(0x400) | CREATE_NEW_PROCESS_GROUP(0x200) | DETACHED_PROCESS(0x8) considering endianness |
My understanding of the problem is that the server being detached and not having a window, when itself spawns new processes, that may create a new window for the new process. I can imagine removing DETACHED_PROCESS might fix it, but I can also see it preventing the server itself from spawning properly in the first place. |
Can you elaborate on this? I've used my fork for a couple months now and I noticed no such issues. |
Isn't the first sccache process blocked until the server ends if you don't use --start-server? |
Ok, poking around, I've convinced myself that the flag that matters the most for my concerns is CREATE_NEW_PROCESS_GROUP, and that removing DETACHED_PROCESS seems fine. |
… process See discussion in mozilla#514.
… process See discussion in mozilla#514.
This is fixed by the merge of #525, but I also just discovered a side effect while I was looking with process explorer, which is that there is now a conhost process attached, which there isn't with DETACHED_PROCESS. Presumably, that's what the things that were opening new windows end up attached to, which is why windows don't show up anymore. |
Actually, there is https://doc.rust-lang.org/std/os/windows/process/trait.CommandExt.html#tymethod.creation_flags |
Interestingly, add |
Humorously, that exists because I implemented it after having to do this the hard way when originally writing the Rust port of sccache. 🙂 |
At this point, I think we can't do better than the current (new) status, but I'll keep this open to still further investigate. |
I had a chat with I can dig into this once I've perused through the remaining open PRs, but if someone else would like to snatch this up, then that would allow the next release to be pushed out faster - I'd like for the fix for this to be included as part of it. |
I am on Windows Server 2022, sccache 21185d9, Rust msvc toolchain. I cannot reproduce the issue. Neither with cmd.exe, nor with PowerShell. I used sccache on a Maybe this is because I start the server separately. I'll test later what happens if I let sccache start the server automatically. |
I've also tested what happens if the let sccache start the server automatically. I still cannot reproduce the issue. I've also researched the history of this issue, the relevant Windows APIs, and sccache's codebase as of commit 21185d9. I believe that this issue is now solved. Here's how I arrived at this conclusion: How does the Windows console work?Windows differentiates between console apps and GUI apps. Windows knows whether an app is a console or a GUI app based on a marker in the executable that's set during linking. What happens when one starts a console app:
Okay let's say a console app (A) is started with But let's say console app A is started with Note that if both Why do I think the issue is now solved?sccache appears to have two places that start console processes (and thus that can potentially make Windows create consoles):
Since I believe this issue can now be closed. Other remarksI don't think |
I continued researching in order to further verify, or falsify, my hypothesis that the issue is now solved. Artificially reproducing the problemI can't reproduce the problem. But is that because the code is now fixed, or is that because there's something in my environment that prevents the problem from occurring? In order to answer this question, I tried to artificially induce the problem.
After having made these changes, I indeed observed the problem: during an sccache invocation (with the server being auto-started) I observed lots of little console window popups. Thus, I conclude that the use of ConclusionThe conclusion is still: the issue is fixed. |
Thanks for the great investigation comments, those are helpful 👍 I think that this ticket has shifted since its initial report:
So, in summary:
|
Glandium has confirmed that he's comfortable deferring this ticket to a future release once we narrow down if there's still any possible improvement here. |
I've researched the conhost issue. What is conhost?Conhost is a process that manages a console and its I/O. When you run cmd.exe and you see that black window — that's a console, backed by one conhost process. Each console is backed by a different conhost process. Normally, a cmd.exe or PowerShell session is backed by one conhost process. When you run additional CLI processes from cmd.exe/PowerShell, they make use of the same console that cmd.exe/PowerShell also uses (they inherit the console), and so there is only one conhost process. Conhost and
|
Nice, good dig, thanks @FooBarWidget! A couple things:
|
Correct.
This is not viable. The only flag that extends to subprocesses is |
Assuming no other Windows shenanigans to influence transitive descendent processes, |
Fixes mozilla#514 (comment) (comment 2022-03-08 by @mitchhentges) Any console-based subprocess spawned with CREATE_NO_WINDOW actually has a hidden console, and thus an associated conhost process. Since the sccache server is already started with CREATE_NO_WINDOW, it's unnecessary to spawn further subprocesses with CREATE_NO_WINDOW. Removing this flag allows subprocesses to share the sccache server's hidden console, thus avoiding each subprocess from getting its own conhost. For an extended explanation see this comment and its follow-ups: mozilla#514 (comment)
Fixes mozilla#514 (comment) (comment 2022-03-08 by @mitchhentges) Any console-based subprocess spawned with CREATE_NO_WINDOW actually has a hidden console, and thus an associated conhost process. Since the sccache server is already started with CREATE_NO_WINDOW, it's unnecessary to spawn further subprocesses with CREATE_NO_WINDOW. Removing this flag allows subprocesses to share the sccache server's hidden console, thus avoiding each subprocess from getting its own conhost. For an extended explanation see this comment and its follow-ups: mozilla#514 (comment)
Fixes #514 (comment) (comment 2022-03-08 by @mitchhentges) Any console-based subprocess spawned with CREATE_NO_WINDOW actually has a hidden console, and thus an associated conhost process. Since the sccache server is already started with CREATE_NO_WINDOW, it's unnecessary to spawn further subprocesses with CREATE_NO_WINDOW. Removing this flag allows subprocesses to share the sccache server's hidden console, thus avoiding each subprocess from getting its own conhost. For an extended explanation see this comment and its follow-ups: #514 (comment)
Fixes mozilla#514 (comment) (comment 2022-03-08 by @mitchhentges) Any console-based subprocess spawned with CREATE_NO_WINDOW actually has a hidden console, and thus an associated conhost process. Since the sccache server is already started with CREATE_NO_WINDOW, it's unnecessary to spawn further subprocesses with CREATE_NO_WINDOW. Removing this flag allows subprocesses to share the sccache server's hidden console, thus avoiding each subprocess from getting its own conhost. For an extended explanation see this comment and its follow-ups: mozilla#514 (comment)
This was previously reported under #16 and supposedly fixed in this commit and again in #472 (which I presume was included in the
0.2.10
release), but the issue still persists - upon the start of a compilation process (in particular, acargo
invocation), multiple console windows pop up for a split second.I'm encountering this with the following environment:
sccache
version0.2.11
installed throughcargo
(it also occured with0.2.10
and previous versions)10.0.18362.0
cargo
subcommandsrun
,build
orinstall
, with the environment variableRUSTC_WRAPPER=sccache
set and using the Rustmsvc
toolchain.Please let me know if you need more information.
The text was updated successfully, but these errors were encountered: