Skip to content

Increase stack size for PowerShell 5 #1797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,16 @@ public PsesInternalHost(
_runspaceStack = new Stack<RunspaceFrame>();
_cancellationContext = new CancellationContext();

_pipelineThread = new Thread(Run)
// Default stack size on .NET Framework is 524288 (512KB) (as reported by GetProcessDefaultStackSize)
// this leaves very little room in the stack. Windows PowerShell internally sets the value based on
// PipelineMaxStackSizeMB as seen here: https://github.com/PowerShell/PowerShell/issues/1187,
// which has default of 10 and multiplies that by 1_000_000, so the default stack size is
// 10_000_000 (~10MB) when starting in normal console host.
//
// For PS7 the value is ignored by .NET because settings the stack size is not supported, but we can
// still provide 0, which means fallback to the default in both .NET and .NET Framework.
int maxStackSize = VersionUtils.IsPS5 ? 10_000_000 : 0;
_pipelineThread = new Thread(Run, maxStackSize)
{
Name = "PSES Pipeline Execution Thread",
};
Expand Down