Cap CollectString/CollectStreams so print loops can't OOM the host#558
Open
Shaurya-Sethi wants to merge 3 commits into
Open
Cap CollectString/CollectStreams so print loops can't OOM the host#558Shaurya-Sethi wants to merge 3 commits into
Shaurya-Sethi wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 9 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Merging this PR will not alter performance
Comparing Footnotes
|
Charge per-entry overhead toward the host cap, keep a running collected_bytes counter, tighten the streams MemoryError assertion, and fix the print.md typo.
Codecov flagged uncovered io.rs lines: collect_streams constructor and append_streams_char / CollectString stdout_push. Prior tests used end='' so terminators never ran.
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
CollectString/CollectStreamsbuffers at 10 MiB by default (max_bytes=Noneto opt out), sinceResourceLimits.max_memoryonly tracks the Monty heap and does not protect parent-process collectors (PrintWriter::CollectStringandPrintWriter::CollectStreamsprobably need to have a size check #464).PrintWriterand PythonPrintTarget::write_event(pool host path); exceeding raisesMemoryErrorwith the familiarmemory limit exceeded: …message.limitations/print.md.Test plan
cargo test -p monty --test print_collect_limits --test print_writercargo test -p monty --test repl call_function_captures_print -- --exactmake format-rs/make lint-rsuv run pytest crates/monty-python/tests/test_print.py::test_collect_string_max_bytes_raises(and existing collector tests)make lint-py(withCONDA_PREFIXunset if needed)Summary by cubic
Add a 10 MiB default cap to host-side print collectors (
CollectString,CollectStreams) so print loops can’t OOM the host. PythonCollectStreamscharges a fixed per-entry overhead and tracks bytes in O(1); usemax_bytes=Noneto opt out (issue #464).New Features
DEFAULT_MAX_PRINT_COLLECT_BYTES(10 MiB). Exceeding raisesMemoryErrorwith “memory limit exceeded: {used} bytes > {limit} bytes”. Not covered byResourceLimits.max_memory.check_print_collect_limit; integrated caps intoPrintWriter::{CollectString, CollectStreams}(now carryOption<usize>); helpersPrintWriter::collect_stringandPrintWriter::collect_streams; exportedDEFAULT_MAX_PRINT_COLLECT_BYTES. Tests now cover helper constructors and newline-push limit paths.CollectString(max_bytes=...)andCollectStreams(max_bytes=...)(default 10 MiB), enforced inPrintTarget::write_event.CollectStreamscharges a 64-byte per-entry overhead with a runningcollected_bytescounter.pyi/docs updated; regression tests added.Migration
PrintWriter::collect_string(&mut buf)orPrintWriter::collect_streams(&mut vec)(or pass an explicitOption<usize>to the variants).CollectString(max_bytes=None)/CollectStreams(max_bytes=None); Rust passNoneto the corresponding variant.Written for commit 9b649cb. Summary will update on new commits.