ConPTY host lingers when all connected clients have been terminated #6410

Closed
opened 2026-01-31 00:37:50 +00:00 by claunia · 6 comments
Owner

Originally created by @grubba on GitHub (Feb 13, 2020).

Description of the new feature/enhancement

On POSIX systems the master end will receive an EOF when all processes that use the slave have terminated or closed the connection. With ConPTY this does not appear to happen, as the pty handling process continues running (and could be used to start new processes). Closing the ConPTY will generate an EOF, but also terminate any remaining processes and possibly lose pending output.

Currently a master that does a blocking read from a ConPTY pipe will hang indefinitely when all slaves have terminated.

Proposed technical implementation details (optional)

Suggestion:

Add an API call to check whether a ConPTY is idle and has no active clients or pending data, and thus is safe to close, or in the alternative add an API call to ask the ConPTY to terminate as soon as its client count reaches zero and not output is pending.

Originally created by @grubba on GitHub (Feb 13, 2020). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> # Description of the new feature/enhancement On POSIX systems the master end will receive an EOF when all processes that use the slave have terminated or closed the connection. With ConPTY this does not appear to happen, as the pty handling process continues running (and could be used to start new processes). Closing the ConPTY will generate an EOF, but also terminate any remaining processes and possibly lose pending output. Currently a master that does a blocking read from a ConPTY pipe will hang indefinitely when all slaves have terminated. <!-- A clear and concise description of what the problem is that the new feature would solve. Describe why and how a user would use this new functionality (if applicable). --> # Proposed technical implementation details (optional) Suggestion: Add an API call to check whether a ConPTY is idle and has no active clients or pending data, and thus is safe to close, or in the alternative add an API call to ask the ConPTY to terminate as soon as its client count reaches zero and not output is pending. <!-- A clear and concise description of what you want to happen. -->
Author
Owner

@DHowett-MSFT commented on GitHub (Feb 13, 2020):

So, funny enough, this is actually supposed to work properly. The handles servicing the PTY should get EOF when the last connected application goes away. We recently made some changed in this area (can't find the bug/PR right now) that resulted in significantly more regressions than we were comfortable with, but it's definitely on our radar.

Thanks!

@DHowett-MSFT commented on GitHub (Feb 13, 2020): So, funny enough, this _is_ actually supposed to work properly. The handles servicing the PTY should get EOF when the last connected application goes away. We recently made some changed in this area (can't find the bug/PR right now) that resulted in significantly more regressions than we were comfortable with, but it's definitely on our radar. Thanks!
Author
Owner

@DHowett-MSFT commented on GitHub (Feb 13, 2020):

Shortest possible version of the explanation: the pty host is holding a ConDrv device reference handle, and conhost thinks there's still a client connected because of it. 😄

@DHowett-MSFT commented on GitHub (Feb 13, 2020): Shortest possible version of the explanation: the pty host is holding a ConDrv device reference handle, and conhost thinks there's still a client connected because of it. :smile:
Author
Owner

@DHowett-MSFT commented on GitHub (Feb 14, 2020):

This is going to have to be fixed at the same time as #1810. /cc @miniksa; i've triaged this into the same milestone at 1810.

@DHowett-MSFT commented on GitHub (Feb 14, 2020): This is going to have to be fixed at the same time as #1810. /cc @miniksa; i've triaged this into the same milestone at 1810.
Author
Owner

@grubba commented on GitHub (Feb 17, 2020):

This seems to me to have the potential for a race condition when starting multiple short-lived processes on the same ConPTY. I guess you could start a long-lived process (eg hanging on a read on a stdin pipe) first, and then the payload processes, and then terminating the first process by closing its stdin.

@grubba commented on GitHub (Feb 17, 2020): This seems to me to have the potential for a race condition when starting multiple short-lived processes on the same ConPTY. I guess you could start a long-lived process (eg hanging on a read on a stdin pipe) first, and then the payload processes, and then terminating the first process by closing its stdin.
Author
Owner

@zhiburt commented on GitHub (Aug 19, 2021):

As I understand it's not yer resolved, right?

But what is the proper way to read all output of a process then?
As if we will continuously read eventually we will block.

Thank you

@zhiburt commented on GitHub (Aug 19, 2021): As I understand it's not yer resolved, right? But what is the proper way to read all output of a process then? As if we will continuously read eventually we will block. Thank you
Author
Owner

@ghost commented on GitHub (Jan 24, 2023):

:tada:This issue was addressed in #14544, which has now been successfully released as Windows Terminal Preview v1.17.1023.🎉

Handy links:

@ghost commented on GitHub (Jan 24, 2023): :tada:This issue was addressed in #14544, which has now been successfully released as `Windows Terminal Preview v1.17.1023`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v1.17.1023) * [Store Download](https://www.microsoft.com/store/apps/9n8g5rfz9xk3?cid=storebadge&ocid=badge)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#6410