Skip to content

Commit dfca531

Browse files
authored
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.
1 parent 3a1b2b4 commit dfca531

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/Worker.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,13 @@ public async static Task Main(string[] args)
7979
}
8080
});
8181

82+
// This must be done before the first Runspace is created, to avoid the creation of a thread by the upgrade checker
83+
SetVersionUpgradeOptOut();
84+
8285
// Create the very first Runspace so the debugger has the target to attach to.
8386
// This PowerShell instance is shared by the first PowerShellManager instance created in the pool,
8487
// and the dependency manager (used to download dependent modules if needed).
88+
8589
var firstPowerShellInstance = Utils.NewPwshInstance();
8690
var pwshVersion = Utils.GetPowerShellVersion(firstPowerShellInstance);
8791
LogPowerShellVersion(pwshVersion);
@@ -101,6 +105,15 @@ public async static Task Main(string[] args)
101105
await requestProcessor.ProcessRequestLoop();
102106
}
103107

108+
private static void SetVersionUpgradeOptOut()
109+
{
110+
string checkForUpgrade = Environment.GetEnvironmentVariable("AZUREPS_CHECK_FOR_UPGRADE");
111+
if (string.IsNullOrWhiteSpace(checkForUpgrade))
112+
{
113+
Environment.SetEnvironmentVariable("AZUREPS_CHECK_FOR_UPGRADE", "False");
114+
}
115+
}
116+
104117
// Warm up the PowerShell instance so that the subsequent function load and invocation requests are faster
105118
private static void WarmUpPowerShell(System.Management.Automation.PowerShell firstPowerShellInstance)
106119
{

0 commit comments

Comments
 (0)