-
Notifications
You must be signed in to change notification settings - Fork 9.2k
ReadConsoleInput can read 0 characters and return success and it almost certainly shouldn't #15859
Description
More discussion notes in dotnet/runtime#88697. I'm filing this here so we have a local reference to the discussion, even if we just close this out.
Here are some miscellaneous noted comments from that thread:
The
Console.ReadKeyfunction can throw anInvalidOperationExceptionwhen "application does not have a console or when console input has been redirected". That makes sense. However, there is another case where it throws anInvalidOperationException, which happens when there are multiple processes attached to the same console, both waiting for input, and one dies or is killed.
BTW it's interesting that the official docs say that it's impossible to read
0characters on success:The function does not return until at least one input record has been read.
Is it a doc bug, or a code bug?
Bear with me as I collect some notes
ApiDispatchers::ServerGetConsoleInputlooks like the guy that handlesReadConsoleInputmicrosoft/terminal@b556594/src/server/ApiDispatchers.cpp#L127-L140That calls into
ApiRoutines::GetConsoleInputImplmicrosoft/terminal@b556594/src/host/directio.cpp#L73-L78That always passes
WaitForDataastrue, in the read from the input buffer. Doc comment on that method:
// - WaitForData - if true, wait until an event is input (if there aren't enough to fill client buffer). if false, return immediatelyoh but then I think we start getting into the realm of the console read waits. Those are nasty to try and track down. My gut says it's not impossible that there's a case where a client disconnecting might try to complete the other waits that were pending. Tracking that down would be trickier. I also have no idea which is right, certainly not off the top of my head.