From 4f62d6122261442a66250ea83b8fdde75cb09066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Wed, 11 May 2022 12:39:24 +0200 Subject: [PATCH] Increase stack size for PS5 --- .../Services/PowerShell/Host/PsesInternalHost.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs b/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs index 64abf455d..3467b80aa 100644 --- a/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs +++ b/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs @@ -112,7 +112,16 @@ public PsesInternalHost( _runspaceStack = new Stack(); _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", };