Conversation
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>
|
The CDT-side fix for debug mode is up as eclipse-cdt/cdt#1522. GDB inferiors run on a |
There was a problem hiding this comment.
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
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.
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>
f0ad977 to
a304eff
Compare
|
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 ;) |
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>


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, orwhile ((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.InputReadJobcopies 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, callIStreamsProxy2.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 beforecloseInputStream()reaches the stream before it is closed.MockProcessnow records whether its stdin was closed.Both new tests fail without the corresponding production change. All
org.eclipse.debug.tests.console.*Testspass (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
PersistentPTYthat ignoresclose(); a separate PR against eclipse-cdt/cdt follows.🤖 Generated with Claude Code