Repository navigation
🐛 fix(query): bound candidate output - #223
Merged
gaborbernat merged 3 commits intoNov 3, 2026
Merged
Conversation
The query timeout did not limit output kept by communicate(). A noisy candidate could exhaust the caller's memory before the timeout. Read each pipe with a separate cap and skip candidates that exceed it. Fixes tox-dev#192.
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.
_run_subprocesscollected candidate output withPopen.communicate(), which buffers all output in memory. The issue reproducer exhausted 1 GiB of caller memory before the 15-second query timeout. This change caps each output stream at 1,048,576 characters and skips candidates that exceed the cap. Fixes #192.Candidate output can exhaust memory before timeout
The old timeout limited how long
communicate()read from a candidate but placed no limit on retained output._collect_query_outputnow drains stdout and stderr concurrently so either pipe can make progress. Each reader stops and kills the candidate after its stream exceeds the cap. One deadline covers both readers and the process wait.Behavior changes
On POSIX and Windows, a candidate that writes beyond either cap produces a query failure, and discovery tries the next candidate.
PY_DISCOVERY_TIMEOUT=infdisables the time limit but retains the output cap. The limit applies before JSON parsing and error formatting.Reported by Anthropic's OSS Scanner: ANT-2026-FJZ4KEUG.