Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Memory leak/memory not released after blob gets downloaded #48037

Open
eusebiu opened this issue Jan 31, 2025 · 2 comments
Open

[BUG] Memory leak/memory not released after blob gets downloaded #48037

eusebiu opened this issue Jan 31, 2025 · 2 comments
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files)

Comments

@eusebiu
Copy link

eusebiu commented Jan 31, 2025

Library name and version

Azure.Storage.Blobs 12.23.0

Describe the bug

After downloading a blob, the memory is not released.

Image

Expected behavior

Memory gets released.

Actual behavior

Memory is not released.

Reproduction Steps

Reproduction steps:

  1. run the code below
  2. notice the memory (see picture)

Code sample:
Console1.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Azure.Storage.Blobs" Version="12.23.0" />
  </ItemGroup>

</Project>

Program.cs

using Azure.Storage.Blobs;
using Azure.Storage;

internal class Program
{
	const string ServiceUrl = "https://modxdev.blob.core.windows.net/";
	const string AccountName = "modxdev";
	const string AccountKey = "<the account key>";

	static BlobServiceClient _CreateBlobServiceClient(string connectionString) => new BlobServiceClient(connectionString);

	static BlobServiceClient _CreateBlobServiceClient(string url, string username, string password)
		=> new BlobServiceClient(new Uri(url), new StorageSharedKeyCredential(username, password));

	public static BlobServiceClient CreateBlobServiceClient(string connectionString, string username, string password)
	{
		return string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password) ?
						_CreateBlobServiceClient(connectionString) : _CreateBlobServiceClient(connectionString, username, password);
	}

	public static BlobContainerClient CreateContainerClient(string connectionString, string containerName, string username, string password)
	{
		var blobServiceClient = CreateBlobServiceClient(connectionString, username, password);
		BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);
		containerClient.CreateIfNotExists();
		return containerClient;
	}

	public static async Task<byte[]?> DownloadBlobContainerItemAsync(string connectionString, string containerName, string name, string username = null, string password = null)
	{
		BlobContainerClient containerClient = CreateContainerClient(connectionString, containerName, username, password);

		BlobClient blobClient = containerClient.GetBlobClient(name);
		using var stream = new MemoryStream();
		await blobClient.DownloadToAsync(stream);
		return stream.ToArray();
	}

	private static async Task Main(string[] args)
	{
		Console.WriteLine("Starting downloading large file (~120MB)...");
	
		await StartDownload();

		Console.WriteLine("Press any key to exit... The memory should be released!");

		Console.ReadKey();
	}

	private static async Task StartDownload()
	{
		var buffer = await DownloadBlobContainerItemAsync(ServiceUrl, "a16ba20e-2c85-4f64-ab85-08dd4173a63f", "output.json", AccountName, AccountKey);
		Console.WriteLine("Buffer is unused, so it should be released after the code flow exists this method...");
	}
}

Environment

Windows 11 Enterprise, Microsoft Visual Studio Enterprise 2022 (64-bit) - Current Version 17.12.4, dotnet 9

dotnet --info
.NET SDK:
Version: 9.0.102
Commit: cb83cd4923
Workload version: 9.0.100-manifests.4a54b1a6
MSBuild version: 17.12.18+ed8c6aec5

Runtime Environment:
OS Name: Windows
OS Version: 10.0.22631
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.102\

.NET workloads installed:
[maccatalyst]
Installation Source: VS 17.12.35707.178
Manifest Version: 18.1.9163/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.maccatalyst\18.1.9163\WorkloadManifest.json
Install Type: Msi

[ios]
Installation Source: VS 17.12.35707.178
Manifest Version: 18.1.9163/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.ios\18.1.9163\WorkloadManifest.json
Install Type: Msi

[android]
Installation Source: VS 17.12.35707.178
Manifest Version: 35.0.7/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.android\35.0.7\WorkloadManifest.json
Install Type: Msi

[aspire]
Installation Source: VS 17.12.35707.178
Manifest Version: 8.2.2/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.2.2\WorkloadManifest.json
Install Type: Msi

[maui-windows]
Installation Source: VS 17.12.35707.178
Manifest Version: 9.0.14/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.maui\9.0.14\WorkloadManifest.json
Install Type: Msi

Configured to use loose manifests when installing new manifests.

Host:
Version: 9.0.1
Architecture: x64
Commit: c8acea2262

.NET SDKs installed:
9.0.102 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

@github-actions github-actions bot added Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files) labels Jan 31, 2025
Copy link

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @xgithubtriage.

@eusebiu
Copy link
Author

eusebiu commented Jan 31, 2025

Adding a GC.Collect() does not help...

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

No branches or pull requests

1 participant