From dc72fa6e00d5d09b69c678e044b7a1bb6b15820b Mon Sep 17 00:00:00 2001 From: andystaples <77818326+andystaples@users.noreply.github.com> Date: Fri, 22 Sep 2023 13:00:18 -0600 Subject: [PATCH] Env variable logic for AZ PS upgrade notification (#1001) Set AZUREPS_CHECK_FOR_UPGRADE environment variable to False unless otherwise specified in App Settings, to prevent an expensive check for available version upgrades by AZ PS. --- src/Worker.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Worker.cs b/src/Worker.cs index e11b501c..7764e867 100644 --- a/src/Worker.cs +++ b/src/Worker.cs @@ -79,9 +79,13 @@ public async static Task Main(string[] args) } }); + // This must be done before the first Runspace is created, to avoid the creation of a thread by the upgrade checker + SetVersionUpgradeOptOut(); + // Create the very first Runspace so the debugger has the target to attach to. // This PowerShell instance is shared by the first PowerShellManager instance created in the pool, // and the dependency manager (used to download dependent modules if needed). + var firstPowerShellInstance = Utils.NewPwshInstance(); var pwshVersion = Utils.GetPowerShellVersion(firstPowerShellInstance); LogPowerShellVersion(pwshVersion); @@ -101,6 +105,15 @@ public async static Task Main(string[] args) await requestProcessor.ProcessRequestLoop(); } + private static void SetVersionUpgradeOptOut() + { + string checkForUpgrade = Environment.GetEnvironmentVariable("AZUREPS_CHECK_FOR_UPGRADE"); + if (string.IsNullOrWhiteSpace(checkForUpgrade)) + { + Environment.SetEnvironmentVariable("AZUREPS_CHECK_FOR_UPGRADE", "False"); + } + } + // Warm up the PowerShell instance so that the subsequent function load and invocation requests are faster private static void WarmUpPowerShell(System.Management.Automation.PowerShell firstPowerShellInstance) {