Skip to content

Prevent inherited input stream from being closed on Windows (fixes #1115)#1213

Open
gnodet wants to merge 1 commit intomasterfrom
fix-issue-1115
Open

Prevent inherited input stream from being closed on Windows (fixes #1115)#1213
gnodet wants to merge 1 commit intomasterfrom
fix-issue-1115

Conversation

@gnodet
Copy link
Member

@gnodet gnodet commented Apr 29, 2025

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 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.

@gnodet gnodet force-pushed the fix-issue-1115 branch 2 times, most recently from 92bb9c4 to 5462f7a Compare April 29, 2025 17:55
@gnodet gnodet changed the title Fix issue #1115: Prevent inherited input stream from being closed on Windows fix: Prevent inherited input stream from being closed on Windows (fixes #1115) Apr 29, 2025
@gnodet gnodet added the bug label Apr 30, 2025
@gnodet gnodet changed the title fix: Prevent inherited input stream from being closed on Windows (fixes #1115) Prevent inherited input stream from being closed on Windows (fixes #1115) Apr 30, 2025
@gnodet gnodet force-pushed the fix-issue-1115 branch from 5462f7a to 295a36d Compare May 9, 2025 18:55
@gnodet gnodet marked this pull request as draft July 7, 2025 06:36
#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.
@gnodet gnodet marked this pull request as ready for review February 15, 2026 20:22
@gnodet
Copy link
Member Author

gnodet commented Feb 15, 2026

augment review

@augmentcode
Copy link

augmentcode bot commented Feb 15, 2026

🤖 Augment PR Summary

Summary: Prevents a Windows-specific issue where probing system streams via subprocesses could close the parent process’s inherited stdin.

Changes:

  • Refactors ExecTerminalProvider.isPosixSystemStream to avoid inheritIO() on Windows by selectively inheriting only the stream being tested.
  • Updates systemStreamName to avoid inheriting stdin on Windows when checking SystemStream.Input, using System.console() instead.

Technical Notes: Non-Windows behavior remains unchanged, while Windows uses explicit ProcessBuilder redirects to reduce risk of closing inherited streams.

🤖 Was this summary useful? React with 👍 or 👎

Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 1 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

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;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant