Repository navigation
Keep a plugin's stderr in a fixed amount of memory - #149
Merged
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Closing the reader does not throw, on any of the three platforms CI runs: the catch around it was never entered.
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.
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.PluginConnectionruns that drain in place ofBeginErrorReadLine.Failurewaits for the drain itself, with the 500 ms deadline it had;Disposeends the drain and closes the pipe.What a caller can see
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).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
ageis now v1.4.0, whoseage-keygenmakes post-quantum keys by default. CI pins v1.3.2.