Repository navigation
Handle a closed stdout like HotSpot - #10
Conversation
…pot does, instead of exiting.
|
Caution Review failedThe pull request is closed. Summary
Merge Risk:
|
There was a problem hiding this comment.
The PR adds handling for closed stdout/stderr pipes to match HotSpot behavior: when the reader closes the pipe (e.g., java-web Main | head -1), writes now throw IOException("Broken pipe") instead of crashing Node with an unhandled error event. A hostOut wrapper installs an error listener on process.stdout/process.stderr; once an error occurs, subsequent writes throw a PendingThrow that the JVM converts to a Java IOException. A new test (Pipe.java) writes many lines, sleeps to let the event loop process the pipe closure, then verifies System.out.checkError() and raw FileOutputStream behavior match HotSpot. The test passes and typecheck is clean.
review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict approve
java-web Main | head -1crashed with node's "Unhandled 'error' event" and exit code 1 onceheadclosed the pipe. HotSpot keeps running:System.outsets its error flag (checkError()is true), a rawFileOutputStreamon fd 1 throwsIOException: Broken pipe, and the exit code is the program's.The Node entry now listens for errors on its stdout and stderr and, once one fails, throws
IOException("Broken pipe")from later writes. Node never marks its stdio streams destroyed and reports each failed write on the next event loop turn, so writes made before that turn are dropped silently rather than failing; the program still runs to the end, as on HotSpot.A new test closes the reader after the first chunk and compares stderr and the exit code with HotSpot; it fails without this change.
Verified: the new test (4 runs),
pnpm typecheck.