From 5d541454c37f6377995ee285ebb0185bf6383939 Mon Sep 17 00:00:00 2001 From: Vincent Dai <23257217+vidai-msft@users.noreply.github.com> Date: Thu, 5 Mar 2026 11:23:14 +0800 Subject: [PATCH] fix: resolve TypeTable race in live test RunspacePool Move type loading from Update-TypeData -AppendPath in AzError.ps1 to TypesToProcess in Az.Accounts.psd1. The -AppendPath path triggers ProcessTypeFiles() which performs a non-atomic Read-Clear-Rebuild on the shared RunspacePool TypeTable, corrupting engine ETS types (e.g. Job.State) when multiple workers concurrently import Az.Accounts. TypesToProcess is loaded via Import-Module Bind(updateOnly=true) which never calls TypeTable.Clear(), eliminating the race. This is the idiomatic PowerShell pattern, consistent with Az.Sql and Az.Functions. Also re-enables the Assert-AreEqual on Job.State in FileTests.ps1 that was commented out as a workaround. --- src/Accounts/Accounts/Az.Accounts.psd1 | 2 +- src/Accounts/Accounts/StartupScripts/AzError.ps1 | 4 +--- src/Storage/LiveTests/Storage.Management/FileTests.ps1 | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Accounts/Accounts/Az.Accounts.psd1 b/src/Accounts/Accounts/Az.Accounts.psd1 index 9ef89e05849e..09880967fb27 100644 --- a/src/Accounts/Accounts/Az.Accounts.psd1 +++ b/src/Accounts/Accounts/Az.Accounts.psd1 @@ -85,7 +85,7 @@ RequiredAssemblies = 'Microsoft.Azure.PowerShell.AssemblyLoading.dll', # ScriptsToProcess = @() # Type files (.ps1xml) to be loaded when importing this module -# TypesToProcess = @() +TypesToProcess = 'Accounts.types.ps1xml' # Format files (.ps1xml) to be loaded when importing this module FormatsToProcess = 'Accounts.format.ps1xml', 'Accounts.generated.format.ps1xml' diff --git a/src/Accounts/Accounts/StartupScripts/AzError.ps1 b/src/Accounts/Accounts/StartupScripts/AzError.ps1 index d0af60d318b0..6c4a9cfb37e1 100644 --- a/src/Accounts/Accounts/StartupScripts/AzError.ps1 +++ b/src/Accounts/Accounts/StartupScripts/AzError.ps1 @@ -59,6 +59,4 @@ if (Get-Module AzureRM.profile -ErrorAction Ignore) "If you are running in Azure Automation, take care that none of your runbooks import both Az and AzureRM modules. More information can be found here: https://aka.ms/azps-migration-guide.") throw ("AzureRM.Profile already loaded. Az and AzureRM modules cannot be imported in the same session or used in the same script or runbook. If you are running PowerShell in an environment you control you can use the 'Uninstall-AzureRm' cmdlet to remove all AzureRm modules from your machine. " + "If you are running in Azure Automation, take care that none of your runbooks import both Az and AzureRM modules. More information can be found here: https://aka.ms/azps-migration-guide.") -} - -Update-TypeData -AppendPath (Join-Path (Get-Item $PSScriptRoot).Parent.FullName Accounts.types.ps1xml) -ErrorAction Ignore \ No newline at end of file +} \ No newline at end of file diff --git a/src/Storage/LiveTests/Storage.Management/FileTests.ps1 b/src/Storage/LiveTests/Storage.Management/FileTests.ps1 index df7712d5d103..c9217d6979ee 100644 --- a/src/Storage/LiveTests/Storage.Management/FileTests.ps1 +++ b/src/Storage/LiveTests/Storage.Management/FileTests.ps1 @@ -26,7 +26,7 @@ Invoke-LiveTestScenario -Name "File basics" -Description "Test File basic operat $t | Wait-Job $t | Receive-Job - # Assert-AreEqual "Completed" $t.State + Assert-AreEqual "Completed" $t.State Assert-Null $t.Error # upload/remove file/dir with -DisAllowTrailingDot @@ -75,7 +75,7 @@ Invoke-LiveTestScenario -Name "File basics" -Description "Test File basic operat $t | Wait-Job $t | Receive-Job - # Assert-AreEqual "Completed" $t.State + Assert-AreEqual "Completed" $t.State Assert-Null $t.Error Assert-AreEqual (Get-FileHash -Path $localDestFile -Algorithm MD5).Hash (Get-FileHash -Path $testfile512path -Algorithm MD5).Hash