Azure / azure-storage-net-data-movement

Azure Storage Data Movement Library for .Net
MIT License
276 stars 132 forks source link

Hang in DMLib when "System.Windows.Forms.Form" is loaded. #280

Open EmmaZhu opened 3 years ago

EmmaZhu commented 3 years ago

Which service(blob, file) does this issue concern?

All

Which version of the SDK was used?

Latest

On which platform were you using? (.Net Framework version or .Net Core version, and OS version)

.Net 4.5 , Windows

How can the problem be reproduced? It'd be better if the code caused the problem can be shared.

What problem was encountered?

We got an issue in PowerShell here: https://github.com/Azure/azure-powershell/issues/15556 . the issue can be reproduced by following script:

$sourceBlobPath = "<sourceblobUri>"
$destFilepath = "localpath\tempblob.tmp"

// Please change following path to library locations in your environment.
$sdks = @(
"C:\Users\emmazhu\.nuget\packages\microsoft.azure.storage.common\11.2.2\lib\netstandard2.0\Microsoft.Azure.Storage.Common.dll", 
"C:\Users\emmazhu\.nuget\packages\microsoft.azure.keyvault.core\2.0.4\lib\netstandard1.5\Microsoft.Azure.KeyVault.Core.dll",
"C:\Users\emmazhu\.nuget\packages\microsoft.azure.storage.blob\11.2.2\lib\netstandard2.0\Microsoft.Azure.Storage.Blob.dll",
"C:\Users\emmazhu\.nuget\packages\microsoft.azure.storage.file\11.2.2\lib\netstandard2.0\Microsoft.Azure.Storage.File.dll",
"D:\repo\DM\azure-storage-net-data-movement\netcore\Microsoft.Azure.Storage.DataMovement\bin\Debug\netstandard2.0\Microsoft.Azure.Storage.DataMovement.dll"
)

foreach ($s in $sdks )
{
Add-Type -Path $s
}

$uri = [System.Uri]$sourceBlobPath
$blob = New-Object -TypeName Microsoft.Azure.Storage.Blob.CloudPageBlob $uri
$blob.FetchAttributes()

#### repro hang ##############

[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

$UserAdminForm = New-Object System.Windows.Forms.Form

#Clear the dest file
if(test-Path $destFilepath)
{
del $destFilepath
}

$t = [Microsoft.Azure.Storage.DataMovement.TransferManager]::DownloadAsync($blob, $destFilepath);
$t.Wait();

The above script would hang at $t.Wait();. But, if the script doesn't load System.Windows.Forms.Form it won't hang.

We used to think it's a .Net issue and opened an issue in .Net's repository: https://github.com/dotnet/runtime/issues/57104

From .Net's explanation, this is caused by a misuse in DMLib. I tried with change DMLib's code as .Net's suggestions, the hang issue gone.

Open this issue to you to see whether DMLib would need to fix this.

Have you found a mitigation/solution?