Skip to content

Keep a plugin's stderr in a fixed amount of memory - #149

Merged
pscheid92 merged 2 commits into
mainfrom
fix/review-s7-bounded-plugin-stderr
Dec 3, 2026
Merged

pscheid92 merged 2 commits into
mainfrom
fix/review-s7-bounded-plugin-stderr

Conversation

@pscheid92

Copy link
Copy Markdown
Owner

Finding S7 of the review of 2026-11-30.

The problem

The client reads a plugin's stderr to its end, so that the plugin never blocks on a full pipe, and keeps the last 20 lines for the error that reports the plugin's failure. It read them with the framework's line reader (BeginErrorReadLine), which gathers each line whole before handing it over. A plugin that wrote 100 MB to stderr on one line grew the client's heap by 418 MB. go-age keeps none of a plugin's stderr.

The change

  • StderrTail (new) reads the pipe's bytes itself and keeps the last 20 lines, each as far as an error shows it (120 characters) and one character more, so that a cut line is still shown as cut. Everything else is read and dropped.
  • PluginConnection runs that drain in place of BeginErrorReadLine. Failure waits for the drain itself, with the 500 ms deadline it had; Dispose ends the drain and closes the pipe.
  • Lines end where they ended before: at LF, at CR, and at the two together, a CR and its LF arriving apart included.

What a caller can see

  • Nothing in an error's text changes for output that ends in a line break: lines were already cut to 120 characters when shown.
  • A last line the plugin did not end is now shown even while something else (an agent the plugin started) holds stderr open. It used to appear only once stderr had ended.

Tests

  • StderrTailTests: 64 MB on one line through the drain leaves one line of 121 characters and allocates under 1 MB (measured on the draining thread); the line rules, whole and one character at a time; only the last 20 lines; a character of several bytes arriving a byte at a time; a pipe that breaks, is closed or is cancelled ends the drain quietly.
  • PluginProcessTests: a real plugin process writes 4 MB to stderr on one line, gets to the end of it, and the error shows the line cut (Unix only; the plugin is a shell script).
  • The review's saved repro (100 MB on one line): heap growth of 418 MB before, none now.

Both suites pass locally in the default and the portable build, apart from one interop test that fails here for an unrelated reason: Homebrew's age is now v1.4.0, whose age-keygen makes post-quantum keys by default. CI pins v1.3.2.

The client reads a plugin's stderr to its end, so the plugin never blocks
on a full pipe, and keeps the last lines for the error that reports the
plugin's failure. The framework's line reader gathered each line whole, so
100 MB on one line grew the heap by 418 MB.

StderrTail reads the pipe's bytes itself and keeps the last 20 lines, each
as far as an error shows it and one character more, so a cut line is still
shown as cut. Lines end where they ended before: at LF, at CR, and at the
two together. A last line the plugin did not end is now shown even while
something else holds stderr open.

Finding S7 of the review of 2026-11-30.
@codecov

codecov Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.72%. Comparing base (1248ab9) to head (7674b35).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #149      +/-   ##
==========================================
+ Coverage   97.65%   97.72%   +0.07%     
==========================================
  Files          77       78       +1     
  Lines        5064     5092      +28     
  Branches      692      697       +5     
==========================================
+ Hits         4945     4976      +31     
+ Misses         73       70       -3     
  Partials       46       46              
Flag Coverage Δ
macos-latest 97.68% <100.00%> (+0.07%) ⬆️
ubuntu-latest 97.68% <100.00%> (+0.07%) ⬆️
windows-latest 97.62% <100.00%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Closing the reader does not throw, on any of the three platforms CI runs:
the catch around it was never entered.
@pscheid92
pscheid92 merged commit d5519e3 into main Dec 3, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant