Skip to content

Send EOF to process when its stdin input file is fully read - #2969

Open
anydoby wants to merge 4 commits into
eclipse-platform:masterfrom
anydoby:stdin-file-eof
Open

anydoby wants to merge 4 commits into
eclipse-platform:masterfrom
anydoby:stdin-file-eof

Conversation

@anydoby

@anydoby anydoby commented Sep 27, 2026

Copy link
Copy Markdown

Problem

When a launch configuration redirects standard input from a file (Common tab → Input File), the program never receives EOF. Programs that read stdin until EOF (e.g. while (scanf(...) == 3) in C, or while ((line = reader.readLine()) != null) in Java) hang forever when launched from Eclipse, while the same program works with shell redirection (./prog < file).

This is the long-standing Bug 513713 and affects all launch types that use the process console (Java, C/C++, …).

Cause

ProcessConsole.InputReadJob copies the input file to the process, but when it reaches the end of the file it just stops; it never closes the process input stream. The only code path that closes it is the console's manual EOF action.

Fix

  • ProcessConsole: once the input file is exhausted, call IStreamsProxy2.closeInputStream(). This only applies to file input; interactive console input is unchanged.
  • InputStreamMonitor: closeInputStream() closed the stream immediately, while data could still be queued for the writer thread, so the tail of the file (or text typed just before the EOF action) could be dropped. Closing is now queued behind the pending data and done by the writer thread. If monitoring hasn't started, the stream is closed immediately as before.

Tests

  • ProcessConsoleTests.testInputFromFileSendsEof: a process with stdin redirected from a file receives the whole content followed by EOF (stdin closed).
  • InputStreamMonitorTests.testCloseInputStreamWritesPendingData: data written before closeInputStream() reaches the stream before it is closed.
  • MockProcess now records whether its stdin was closed.

Both new tests fail without the corresponding production change. All org.eclipse.debug.tests.console.*Tests pass (115 run, 1 skipped as before).

Also verified manually on Linux with a C program (CDT) and a Java program: run mode now terminates at the end of the input file instead of hanging. Debug mode for CDT additionally needs a CDT-side fix, since GDB inferiors use a PersistentPTY that ignores close(); a separate PR against eclipse-cdt/cdt follows.

🤖 Generated with Claude Code

When a launch configuration redirects standard input from a file
(Common tab > Input File), ProcessConsole copied the file to the process
but never closed the process input stream. Programs reading stdin until
EOF therefore never terminated when run from Eclipse, while the same
program worked with shell redirection.

Close the process input stream once the file is exhausted.

InputStreamMonitor.closeInputStream() closed the stream immediately and
dropped data still queued for the writer thread, so the tail of the file
(or text typed right before the console EOF action) could be lost. The
stream is now closed by the writer thread after all pending data is
written.

Fixes https://bugs.eclipse.org/bugs/show_bug.cgi?id=513713

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anydoby

anydoby commented Sep 27, 2026

Copy link
Copy Markdown
Author

The CDT-side fix for debug mode is up as eclipse-cdt/cdt#1522. GDB inferiors run on a PersistentPTY that ignores close(), so without it the EOF from this change (and the console EOF action) never reaches a program being debugged. With both changes, run and debug mode work for C/C++ launches with an input file.

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

    54 files  ±0      54 suites  ±0   57m 50s ⏱️ +33s
 4 838 tests +2   4 816 ✅ +2   22 💤 ±0  0 ❌ ±0 
12 405 runs  +6  12 251 ✅ +6  154 💤 ±0  0 ❌ ±0 

Results for commit 680e981. ± Comparison against base commit 7b37f53.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

A start/close race can strand the writer thread, and changed plug-in versions require manifest increments.

Review effort: Balanced
Findings: 1 High severity · 3 Low severity

Open (4)
What changed in this PR

Fixes redirected stdin so processes receive EOF after the input file is exhausted.

Changes:

  • Sends EOF after file input completes.
  • Queues stream closure behind pending writes.
  • Adds regression tests and EOF tracking.
File Description
ProcessConsole.java Closes process stdin after file exhaustion.
InputStreamMonitor.java Defers closure until queued data is written.
ProcessConsoleTests.java Tests redirected-file EOF behavior.
InputStreamMonitorTests.java Tests write-before-close ordering.
MockProcess.java Tracks stdin closure.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

anydoby and others added 2 commits September 28, 2026 20:16
closeInputStream() set fClosed only after releasing fLock when no writer
thread was running. A concurrent startMonitoring() could start the writer
in that gap; it then saw the stream as open and waited for data forever.
This can happen with an empty stdin input file, where ProcessConsole
requests EOF before RuntimeProcess starts the stream monitors.

Set fClosed under the lock and let the writer stop waiting once the
stream is closed. Also suppress the resource warning in the new test,
the monitor owns and closes the stream.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anydoby

anydoby commented Sep 29, 2026

Copy link
Copy Markdown
Author

Hi @akurtakov, I believe I've addressed the findings by copilot. Good catch. I've observed this bug since 2012 in Eclipse for Java. It's a pity it's still around up to this date ;)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Pending pre-start input can still be discarded when EOF races with monitor startup.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (4)

closeInputStream() closed the stream immediately if no writer thread was
running yet, dropping data that was already queued. ProcessConsole can
write a small stdin input file and request EOF before RuntimeProcess
starts the stream monitors, so the process received EOF without input.

Queue the close after pending data in that case as well; the writer
thread writes it once monitoring starts. The stream is still closed
immediately if nothing is pending and no writer thread exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants