Repository navigation
fix: bound captured script output across execution engines - #633
Merged
Merged
Conversation
Stop process, runspace and WinRM execution when the shared output budget is exceeded. Drain streams incrementally and preserve cancellation semantics. Add Engine:MaxCapturedOutputChars (default 16777216) and regression coverage for oversized and infinite output. Fixes #572
Sev7eNup
force-pushed
the
fix/572-bound-script-output
branch
from
October 24, 2026 15:50
7c5f6fb to
5705ee6
Compare
| if (baseObj is string s) return s; | ||
| try { return baseObj?.ToString() ?? string.Empty; } catch { } | ||
| try { return ps.ToString() ?? string.Empty; } catch { } | ||
| return $"<{baseObj?.GetType().Name ?? "PSObject"}: ToString failed>"; |
| public async Task Capture_ConcurrentStreams_ShareOneBudgetAndContinueDraining() | ||
| { | ||
| using var budget = new ScriptOutputBudget(4096); | ||
| var stdout = new ProcessExecutionEngine.OutputCapture(new StringReader(new string('o', 10000)), |
| using var budget = new ScriptOutputBudget(4096); | ||
| var stdout = new ProcessExecutionEngine.OutputCapture(new StringReader(new string('o', 10000)), | ||
| TestContext.Current.CancellationToken, budget.CreateBuffer()); | ||
| var stderr = new ProcessExecutionEngine.OutputCapture(new StringReader(new string('e', 10000)), |
| { | ||
| var baseObj = ps.BaseObject; | ||
| if (baseObj is string s) return s; | ||
| try { return baseObj?.ToString() ?? string.Empty; } catch { } |
| { | ||
| var baseObj = ps.BaseObject; | ||
| if (baseObj is string s) return s; | ||
| try { return baseObj?.ToString() ?? string.Empty; } catch { } |
| var baseObj = ps.BaseObject; | ||
| if (baseObj is string s) return s; | ||
| try { return baseObj?.ToString() ?? string.Empty; } catch { } | ||
| try { return ps.ToString() ?? string.Empty; } catch { } |
| var baseObj = ps.BaseObject; | ||
| if (baseObj is string s) return s; | ||
| try { return baseObj?.ToString() ?? string.Empty; } catch { } | ||
| try { return ps.ToString() ?? string.Empty; } catch { } |
| return $"<{baseObj?.GetType().Name ?? "PSObject"}: ToString failed>"; | ||
| } | ||
| try { return value.ToString() ?? string.Empty; } | ||
| catch { return $"<{value.GetType().Name}: ToString failed>"; } |
| { | ||
| try { ps.Stop(); } catch { /* best-effort: pipeline may already be torn down */ } | ||
| }); | ||
| _ = Task.Run(() => { try { ps.Stop(); } catch { /* pipeline may already be torn down */ } })); |
2 tasks done
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.
What & why
Stop process, runspace and WinRM execution when the shared output budget is exceeded. Drain streams incrementally and preserve cancellation semantics.
Add Engine:MaxCapturedOutputChars (default 16777216) and regression coverage for oversized and infinite output.
Fixes #572
The default accommodates Start Program's existing two capped 1 MiB streams even with JSON escape expansion. Smaller configured budgets still apply across all streams.
Testing
Engine.Tests:
FullyQualifiedName~PowerShell|FullyQualifiedName~WinRmSession|FullyQualifiedName~StartProgram— 450 passed. Regressions cover shared stream budgets, oversized and endless output, WinRM invalidation, cancellation, and both Start Program streams at their cap including JSON-escaped control characters.git diff --checkpassed. Full CI runs on this PR.