Closed YanaXu closed 5 months ago
The Azure PowerShell Module is supposed to be created and initialized only once in one PS session. But when -Parallel is used, one module could be created and initialized many times. Autorest should handle this situation or it may cause errors.
-Parallel
generation
src\StreamAnalytics\StreamAnalytics.Autorest
autorest
src\StreamAnalytics\StreamAnalytics.Autorest\generated\Module.cs
Init()
Module()
System.Console.WriteLine("[" + System.Diagnostics.Process.GetCurrentProcess().Id + "] [" + System.Threading.Thread.CurrentThread.ManagedThreadId + "] module init");
build-module.ps1
PS azure-powershell\src\StreamAnalytics\StreamAnalytics.Autorest> ipmo .\Az.StreamAnalytics.psd1 [44432] [17] module constructor [44432] [17] module init PS azure-powershell\src\StreamAnalytics\StreamAnalytics.Autorest> 1..3 | % -Parallel { Get-AzStreamAnalyticsJob -ResourceGroupName 'test_rg' -Name 'sajob' } [44432] [21] module init [44432] [25] module init [44432] [24] module init ******
PS azure-powershell\src\StreamAnalytics\StreamAnalytics.Autorest> 1..3 | % -Parallel { ipmo .\Az.StreamAnalytics.psd1; Get-AzStreamAnalyticsJob -ResourceGroupName 'test_rg' -Name 'sajob' } [42592] [22] module constructor [42592] [24] module constructor [42592] [23] module constructor [42592] [23] module init [42592] [24] module init [42592] [22] module init ******
Parallel
Force
PS azure-powershell\artifacts\Debug\Az.StreamAnalytics> ipmo ./Az.StreamAnalytics.psd1 [18520] [18] module constructor [18520] [18] module Init PS azure-powershell\artifacts\Debug\Az.StreamAnalytics> ipmo ./Az.StreamAnalytics.psd1 PS azure-powershell\artifacts\Debug\Az.StreamAnalytics> ipmo ./Az.StreamAnalytics.psd1 -Force [18520] [18] module Init PS azure-powershell\artifacts\Debug\Az.StreamAnalytics> ipmo ./Az.StreamAnalytics.psd1 -Force [18520] [18] module Init
Need to make following two calls only be executed once when executed in multiple threads.
https://github.com/Azure/azure-powershell/blob/5a43ae12cbaa8993b4bc690b33a681e2b36df829/src/Databricks/Databricks.Autorest/generated/Module.cs#L58
https://github.com/Azure/azure-powershell/blob/5a43ae12cbaa8993b4bc690b33a681e2b36df829/src/Databricks/Databricks.Autorest/generated/Module.cs#L118-L123
Fixed in autorest.powershell v4.
The Azure PowerShell Module is supposed to be created and initialized only once in one PS session. But when
-Parallel
is used, one module could be created and initialized many times. Autorest should handle this situation or it may cause errors.Preparation for reproduce
generation
branch.src\StreamAnalytics\StreamAnalytics.Autorest
, runautorest
src\StreamAnalytics\StreamAnalytics.Autorest\generated\Module.cs
, add a print message in methodInit()
andModule()
src\StreamAnalytics\StreamAnalytics.Autorest
, runbuild-module.ps1
.The reproduce steps for case 1
The reproduce steps for case 2
The reproduce steps for case 3 - without
Parallel
but import the module withForce