Close the javac pipes and join the drain threads in externalCompile - #110
Merged
Merged
Conversation
CodeGenUtil.externalCompile never closed any of the three pipes it opened for the compiler process. proc.getOutputStream() (stdin, which javac never reads) was left open, and the BufferedReaders wrapping stdout and stderr in copy() were never closed, so three file descriptors per invocation were held until the Process was collected. The drain threads were also never joined: proc.waitFor() returns as soon as the process exits, which can be before the readers have finished appending, so the compiler diagnostics printed just below could be truncated or empty. The "out" and "err" locals were assigned and then unused. Close stdin up front, join both readers after waitFor(), destroy the process in a finally, and let copy() close its reader when the pipe is drained. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CodeGenUtil.externalCompilenever closed any of the three pipes it opens for the compiler process:proc.getOutputStream()(stdin, whichjavacnever reads) is left open;BufferedReaders wrapping stdout and stderr incopy()are never closed.That is three file descriptors per invocation, released only when the
Processis finally collected.The drain threads were also never joined.
proc.waitFor()returns as soon as the process exits, which can be before the reader threads have finished appending, so the compiler diagnostics printed immediately below could be truncated or empty — theoutanderrlocals were assigned and then never used.This change closes stdin up front, joins both readers after
waitFor(), destroys the process in afinally, and letscopy()close its reader once the pipe is drained.compile.scomp.checkin.CompilationTests(10 tests, all of which shell out tojavacthrough this path) passes.🤖 Generated with Claude Code