Replace shell-based process runner with open3_safe#9
Open
Conversation
c7e7eac to
0a81aca
Compare
0a81aca to
e5b63ee
Compare
Replaces the bash pipe + system timeout binary approach in ExternalProcess#run with Open3Safe.capture3_safe, which provides proper stdout/stderr capture, timeout handling, and RSS-based memory limiting without spawning a shell. - Add open3_safe gem dependency - Propagate max_rss: keyword arg through public API and all extractors - Convert env strings to Hashes for Open3 compatibility - Remove 2>&1 redirects (stderr now captured separately) - Duplicate/blank-line filtering preserved in the new implementation Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
e5b63ee to
59c73e6
Compare
| # Combine stdout+stderr (previously unified via 2>&1 in callers), then filter blank | ||
| # lines and consecutive duplicates. This avoids memory bloat from corrupt PDFs that | ||
| # generate an infinite stream of identical warnings — see silverfin/issues/1998. | ||
| output = (result[:stdout] + result[:stderr]) |
There was a problem hiding this comment.
issue: If AI understands it correctly result[:stderr] isn't a stream but a string already in memory containing the whole error output.
If Ghostscript happens to vomit 500MB+ data to stderr, it will be in Ruby's heap at this point. That is what they wanted to fix in issue #1998.
I guess that's why they added grep -v \"^$\" | uniq to the command so it won't reach Ruby.
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.
Summary
ExternalProcess#run's bash-pipe + systemtimeout/gtimeoutbinary approach withOpen3Safe.capture3_safe, which handles stdout/stderr capture, timeout, and RSS-based memory limiting without spawning an intermediate shellmax_rss:keyword argument throughout the public API (extract_text_with_timeouts,extract_images_with_timeouts) and propagates it down throughTextExtractor,ImageExtractor, and into eachruncall"MAGICK_TMPDIR=... OMP_NUM_THREADS=2") to a proper Hash as required by Open32>&1redirects from all command strings — stderr is now captured separately and merged with stdout after the fact, with the same blank-line and consecutive-duplicate filtering as before (guards against memory bloat from corrupt PDF warning floods — see silverfin/issues/1998)open3_safegem dependency (Gemfile,Gemfile.lock,docsplit.gemspec)Test plan
TimeoutErroris raisedmax_rss:value) and confirmTimeoutErroris raisedpdffontspath incontains_text?works correctly end-to-end🤖 Generated with Claude Code