Prevent inherited input stream from being closed on Windows (fixes #1115)#1213
Prevent inherited input stream from being closed on Windows (fixes #1115)#1213
Conversation
92bb9c4 to
5462f7a
Compare
#1115) The problem occurs because ProcessBuilder.inheritIO() causes the subprocess to inherit all standard streams (stdin, stdout, stderr) from the parent process. When the subprocess terminates, it closes these streams, which can cause issues if the parent process still needs to use them. This fix modifies the isPosixSystemStream and systemStreamName methods in ExecTerminalProvider to handle Windows differently: 1. For isPosixSystemStream: - On Windows: - For SystemStream.Output and SystemStream.Error, we use explicit redirects to avoid inheriting stdin - For SystemStream.Input, we use isWindowsSystemStream which is safer on Windows - On non-Windows platforms, we continue to use inheritIO() as it works fine there 2. For systemStreamName: - On Windows, for SystemStream.Input, we use System.console() to check if stdin is a terminal without using ProcessBuilder - For all other cases, we use the original approach This approach is targeted and minimally invasive, focusing only on fixing the Windows-specific issue while leaving the behavior unchanged for other platforms.
5a69503 to
4eb6c71
Compare
|
augment review |
🤖 Augment PR SummarySummary: Prevents a Windows-specific issue where probing system streams via subprocesses could close the parent process’s inherited stdin. Changes:
Technical Notes: Non-Windows behavior remains unchanged, while Windows uses explicit 🤖 Was this summary useful? React with 👍 or 👎 |
| if (OSUtils.IS_WINDOWS && stream == SystemStream.Input) { | ||
| // On Windows, for stdin, use a safer approach that doesn't inherit stdin | ||
| // This prevents the pipe from being closed | ||
| return System.console() != null ? "console" : null; |
There was a problem hiding this comment.
On Cygwin/MSYS terminals (which this provider explicitly supports in winSysTerminal), System.console() is commonly null even when stdin is a tty; returning null here may make isSystemStream(Input) false and prevent TerminalBuilder from creating a system terminal in those environments.
Severity: high
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
This PR fixes issue #1115 where the inherited input stream is closed when a subprocess terminates on Windows.
The problem occurs because
ProcessBuilder.inheritIO()causes the subprocess to inherit all standard streams (stdin, stdout, stderr) from the parent process. When the subprocess terminates, it closes these streams, which can cause issues if the parent process still needs to use them.This fix modifies the
isPosixSystemStreamandsystemStreamNamemethods inExecTerminalProviderto handle Windows differently:For
isPosixSystemStream:isWindowsSystemStreamwhich is safer on WindowsinheritIO()as it works fine thereFor
systemStreamName:System.console()to check if stdin is a terminal without using ProcessBuilderThis approach is targeted and minimally invasive, focusing only on fixing the Windows-specific issue while leaving the behavior unchanged for other platforms.