-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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 Terminal, Command Prompt, OpenConsole processes cannot be suspended #9704
Comments
We do not control this. Also, why? |
You can suspend other processes perfectly fine except the command prompt so that's a bug that should be looked into?? |
This is likely due to the job object that is created for WT thanks to it being launched inside a package, which is out of our control and isn’t something we can fix. It’s also just not a supported use case: individually stomping processes on your system to make sure they “behave” isn’t a normal part of system administration... |
I can reproduce the same issue with a lot of other software without job objects... Chrome, Msedge, Visual Studio, Discord, Steam, Skype even Windbg which needs to suspend the thread/process to properly capture thread contexts when debugging the console project. The whole point of creating this ticket was so you guys could follow up the problem internally with the kernel team since A) It affects the console and debugging the console, so it's a very relevant bug for this project and B) because it's a recent issue with Windows 10 that breaks everything using the SuspendThread function since 2000 (21 years of backwards compatibility).
SuspendThread has some very valid uses cases outside of administration especially for debugging. I reported this for the above reasons not because of administration. |
It would help us build a case for getting this fixed if we understood your use case, you know? VS and WinDbg don’t seem to have any trouble with Terminal or its subprocesses, and if I understand them properly they’re not using any special APIs for doing so. We’ve been debugging things inside terminal or hosted by OpenConsole (which services console API functions and does not “host” a process in any meaningful way related to its process tree) for the past two years on windows versions 17763 to 21310. I’m not embellishing this point for no reason. It seems like totally normal debugging tools work just fine for us. I’m worried that we’re looking at an XY Problem.
I must have missed in your original report that this was a regression. Sorry about that! 😄 |
My bad. I should have mentioned earlier that it's a regression and it worked fine prior to Windows 10. For example:
It's probably not something that's been noticed/reported until now? Windbg uses GetThreadContext and per MSDN you cannot get a proper valid context for a running thread because of race conditions/other issues which is why suspension is required. If you attach windbg to the command prompt/windows terminal processes then it should suspend the process but doesn't and using some other tools you can see 1 thread never transitions to the Suspended wait state. For example: The suspend count is 1 but that value is just a counter unrelated to the actual suspension: The thread hasn't actually suspended and the KWAIT_REASON for the thread permanently remains Executive instead of transitioning to Suspended (the first thread with ntdll.dll!DbgUiRemoteBreakin is windbg and should be ignored)
The thread is the console calling ReadFile on a pipe and that thread is probably not something that gets debugged very often and since windbg is showing an incorrect suspension state its probably gone unnoticed? It's also the same problem causing Process Explorer and the built-in Resmon tool to not show cmd.exe/WindowsTerminal.exe processes' as suspended because that one thread doesn't transition to the Suspended state like previous versions of Windows. Context switches are also supposed to trigger the suspension but queuing a kernel APC which does execute and causes a context switch/increments the counters also doesn't trigger the suspension.
I guess that's somewhat related. I'm using cmd.exe and WindowsTerminal.exe as an example of the problem but it's not just those two processes that can be used to demonstrate this issue on Windows 10 - I'm only mentioning cmd.exe and WindowsTerminal.exe since this tracker is only for issues related to the console. I did expect the issue to get closed but sort of expected someone would follow up/report the bug internally with whomever owns that kernel code especially since it can be easily reproduced with cmd.exe and Process Explorer when compared to previous versions of Windows? These non-suspendable threads end up deadlocked inside IopSynchronousServiceTail which is also the same code apparently responsible for handling the CTRL+C signals for the console and that function also handles synchronous waits on file objects (such as when cmd.exe is calling ReadFile on a pipe handle - the same thread that doesn't get suspended)... So there might have been some changes for console support on Win10 that also accidently broke thread suspension as a side effect - I can't be sure what changed but these threads would successfully suspend on Win7/Win8 but are now permanently running on Win10 despite calling SuspendThread.
The primary use case is debugging since multiple programs/debuggers are reporting incorrect information. The other primary issue is backwards compatibility since this change on Windows 10 breaks Microsoft's own software (including built-in applications like resmon) and also lots of third party tools released since 2000 (including every version of our own software released over the last 12 years). Hope this helps |
I think this only applies to a synchronous I/O wait, which is an alertable kernel wait in If I had to guess, I'd say this is related to the implementation of
What deadlock? Also, what's the relevance of Ctrl+C? The only connection I see is that, for a conpty session, the Ctrl+C character is read from a pipe, which is a synchronous read. But handling this input by sending a console control event has nothing to do with I/O. The console host simply sends a request to the desktop-session server (csrss.exe in the current session) to request the creation of a control thread in the client. |
That's what should occur in theory but in reality it's continuing to schedule and wait indefinitely without ever transitioning to the suspended state.
The cancellation feature has exited since Vista (2006) but the issue with suspension has only started with recent versions of Win10.
The suspension APC is scheduled to the thread but it never actually executes regardless of how many days/weeks/months you're waiting for the state change which is the a textbook definition of a deadlock.
It does and always has.
The sourcecode for these functions where this deadlock occurs includes specific comments that mention the CTRL+C handling 🤷♂️
This isn't a development issue so they won't be much help and they use my project source as a reference so it would basically become a circle jerk with suggestions of switching to linux without anything on Windows ever getting fixed... The reason I created the issue here was so someone like @DHowett would hopefully follow up/raise this issue internally with his co-workers since this issue affects cmd.exe and debugging cmd.exe compared to OSR where people would just be upset and not able to do anything about it. The only other place for reporting the issue would be using this repository (https://github.com/microsoft/Windows-Dev-Performance) but since the code for the deadlock references the console it might have been a recent change for console support that broke suspension so again I figured reporting it here would be the best place so it could be looked into? |
I poked around a bit. There are a couple of interesting changes relevant to suspending threads. The first change should be a transparent optimization. If The change that's problematic is that, for non-alertable synchronous I/O, system calls such as For example, if you suspend cmd.exe, pressing enter in its console or terminal window should complete its That said, I do not know why non-alertable synchronous I/O is disabling delivery of normal kernel APCs, such as the suspend APC, while the file object's lock is held. What I do know is that, starting with Windows Vista, pended synchronous creates were changed to use an alertable kernel-mode wait in order to support cancellation when the requesting thread is terminated. Moreover, it seems that all synchronous I/O waits were changed to use an alertable kernel-mode wait. (Formerly, for an I/O system call from user mode, the wait for non-alertable synchronous I/O was a non-alertabled user-mode wait.) Thread termination in this case relies on
The Interix (SUA) subsystem has some way to use APCs to implement POSIX signals. The Windows subsystem (or rather its designers), on the other hand, is opposed to the way Unix signals work, which entails executing handlers asynchronously in user mode on a thread that's not in a alertable wait state. Instead, Windows delivers a console control event, such as
The OSR community is for developers of NT device drivers. Like any online forum, I'm sure it has problems with trolls and difficult personalities. But the founding members there, who have been writing NT device drivers for almost 30 years, are better situated to get the attention of the kernel developers at Microsoft. I don't think the terminal/conhost team has the time or inclination to internally report an issue like this and relay feedback to you, but maybe you lucked out here. |
Windows Terminal version (or Windows build number)
10.0.19042.906
Other Software
Command Prompt
Windows Terminal
Open Console
Steps to reproduce
Process Explorer
and/orresmon.exe /res
cmd.exe
WindowsTerminal.exe
OpenConsole.exe
Expected Behavior
The processes are suspended and show with a grey background in Process Explorer like other software.
For example:
Actual Behavior
cmd.exe and WindowsTerminal.exe cannot be suspended. Additionally OpenConsole.exe shows suspended for 5ms before magically becoming unsuspended.
For example:
This is especially problematic with the built-in resource monitor tool since the console process becomes deadlocked after selecting suspend and the process continues running:
The text was updated successfully, but these errors were encountered: