Skip to content

🐛 fix(query): bound candidate output - #223

Merged
gaborbernat merged 3 commits into
tox-dev:mainfrom
gaborbernat:bug/fjz4keug-bounded-output
Nov 3, 2026
Merged

gaborbernat merged 3 commits into
tox-dev:mainfrom
gaborbernat:bug/fjz4keug-bounded-output

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

_run_subprocess collected candidate output with Popen.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_output now 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=inf disables 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.

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.
@gaborbernat gaborbernat added the bug Something isn't working label Nov 3, 2026
@gaborbernat
gaborbernat merged commit 1d88a43 into tox-dev:main Nov 3, 2026
20 checks passed
@gaborbernat
gaborbernat deleted the bug/fjz4keug-bounded-output branch November 3, 2026 01:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Candidate output can exhaust memory before the query timeout

1 participant