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
CommandImplementationto render the markup were hanging whenever large files were provided. So this PR:CommandImplementation#executemethod to handle largestdoutandstderrstreams from called subprocessesWhy?
Previously, the implementation using
popen3would hang in the case of large files. Taking a closer look I tried a few things to see what was going on:rest2htmlprogram, 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 thestdoutbuffer. This of course lead to the wrong return result, but, no hang!rest2htmlback to it's original state, I tried to read thestdoutbuffer withstdout.readlinesbefore thewait_thrvalue. 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 thestdoutbufferstdoutbuffer was full, and therefore wasn't exiting to return a status.The fix
capture3is a wrapper aroundpopen3which creates new threads to read instdoutandstderrwhile waiting for a status to be reported. This means that we don't end up hanging due to a full buffer. Thecapture3implementation can be seen in:https://github.com/ruby/ruby/blob/83f02d42e0a3c39661dc99c049ab9a70ff227d5b/lib/open3.rb#L648-L677