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

CopyObjectAsync memory leak #1170

Open
luanhailiang opened this issue Sep 4, 2024 · 0 comments
Open

CopyObjectAsync memory leak #1170

luanhailiang opened this issue Sep 4, 2024 · 0 comments

Comments

@luanhailiang
Copy link

luanhailiang commented Sep 4, 2024

  public async Task copyFile(string srcObjectName, string destObjectName) {
            string bucketName = "gamedata";
            try {
                CopyObjectArgs copyObjectArgs = new CopyObjectArgs()
                    .WithBucket(bucketName)
                    .WithObject(destObjectName)
                    .WithCopyObjectSource(new CopySourceObjectArgs()
                        .WithBucket(bucketName)
                        .WithObject(srcObjectName));

                await _minio.CopyObjectAsync(copyObjectArgs).ConfigureAwait(false);
            } catch (MinioException e) {
                Console.WriteLine("Error occurred: " + e);
                throw new ApplicationException(e.ToString());
            }
        }

environment

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

    <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
        <InvariantGlobalization>true</InvariantGlobalization>
        <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
        <DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.8" />
        <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.8" />
        <PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.0.2" />
        <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
        <PackageReference Include="Minio" Version="6.0.3" />
        <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
        <PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0" />
        <PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.3" />
        <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.0.2" />
    </ItemGroup>

</Project>

2b5928667967af6461eab8b28d3e720

simple demo just for test copy

using Minio;
using Minio.DataModel.Args;


var endpoint = "127.0.0.1:9000";
var accessKey = "lkk";
var secretKey = "lkk123";
var secure = false;
// Initialize the client with access credentials.
IMinioClient minio = new MinioClient()
                                    .WithEndpoint(endpoint)
                                    .WithCredentials(accessKey, secretKey)
                                    .WithSSL(secure)
                                    .Build();

var BucketName = "gamedata";

try {
    Console.WriteLine("Running example for API: CopyObjectAsync");
    var metaData = new Dictionary<string, string>
        (StringComparer.Ordinal) { { "Test-Metadata", "Test  Test" } };
    // Optionally pass copy conditions
    var guidSave = Guid.NewGuid().ToString();
    var saveObjectName = "copy/" + guidSave;

    File.WriteAllBytes("test.txt", new byte[1024 * 1024]);
    var filestream = File.OpenRead("test.txt");

    var putargs = new PutObjectArgs()
                .WithBucket(BucketName)
                .WithObject(saveObjectName)
                .WithStreamData(filestream)
                .WithObjectSize(filestream.Length)
                .WithContentType("application/octet-stream")
                .WithHeaders(metaData);
    _ = await minio.PutObjectAsync(putargs).ConfigureAwait(false);


    var cpSrcArgs = new CopySourceObjectArgs()
        .WithBucket(BucketName)
        .WithObject(saveObjectName);
    for (int i = 0; i < 500000; i++) {
        var guid = Guid.NewGuid().ToString();
        var destObjectName = "copy/" + guid;
        var copyargs = new CopyObjectArgs()
            .WithBucket(BucketName)
            .WithObject(destObjectName)
            .WithCopyObjectSource(cpSrcArgs);
        await minio.CopyObjectAsync(copyargs).ConfigureAwait(false);
        Console.WriteLine("Copied object {0} from {1} to {2}", i, saveObjectName,destObjectName);
        Console.WriteLine();
    }
} catch (Exception e) {
    Console.WriteLine("[Bucket]  Exception: {0}", e);
}

demo environment

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

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

  <ItemGroup>
    <PackageReference Include="Minio" Version="6.0.3" />
  </ItemGroup>

</Project>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant