Update CommandImplementation to handle large stdout #1808
Closed
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.
What?
Markup renderers which were using the
CommandImplementation
to render the markup were hanging whenever large files were provided. So this PR:CommandImplementation#execute
method to handle largestdout
andstderr
streams from called subprocessesWhy?
Previously, the implementation using
popen3
would hang in the case of large files. Taking a closer look I tried a few things to see what was going on:rest2html
program, instead of writing the results of a large RST file tostdout
, I processed the file, wrote it to a file, and just wrote a random short string (asdf
) to thestdout
buffer. This of course lead to the wrong return result, but, no hang!rest2html
back to it's original state, I tried to read thestdout
buffer withstdout.readlines
before thewait_thr
value. This also lead to no hang.Based on these 2, we can see that the python and ruby sides were causing one another to hang:
wait_thr.value.success?
before reading thestdout
bufferstdout
buffer was full, and therefore wasn't exiting to return a status.The fix
capture3
is a wrapper aroundpopen3
which creates new threads to read instdout
andstderr
while waiting for a status to be reported. This means that we don't end up hanging due to a full buffer. Thecapture3
implementation can be seen in:https://github.com/ruby/ruby/blob/83f02d42e0a3c39661dc99c049ab9a70ff227d5b/lib/open3.rb#L648-L677