最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

There is a problem with descriptor leaks when copyingdeleting objects in Minio .Net - Stack Overflow

programmeradmin1浏览0评论

I wrote a test console application in C# that renames the same file on a Minio server.

My code:

class Program
{
   private static readonly string bucketName = "my-bucket";
   private static readonly IMinioClient minioClient = new MinioClient()
       .WithEndpoint("localhost:9100")  
       .WithCredentials("minioadmin", "minioadmin")
       .Build();

   public static async Task RenameFileAsync(string oldObjectName, string newObjectName, CancellationToken token)
   {
       try
       {
          
           using var cts = CancellationTokenSource.CreateLinkedTokenSource(token);
           cts.CancelAfter(TimeSpan.FromSeconds(30));

           
           var copySourceArgs = new CopySourceObjectArgs()
               .WithBucket(bucketName)
               .WithObject(oldObjectName);

           var copyObjectArgs = new CopyObjectArgs()
               .WithCopyObjectSource(copySourceArgs)
               .WithBucket(bucketName)
               .WithObject(newObjectName);

           await minioClient.CopyObjectAsync(copyObjectArgs, cts.Token);
           Console.WriteLine($"[{DateTime.Now}] Copied {oldObjectName} → {newObjectName}");

          
           var removeObjectArgs = new RemoveObjectArgs()
               .WithBucket(bucketName)
               .WithObject(oldObjectName);

           await minioClient.RemoveObjectAsync(removeObjectArgs, cts.Token);
           Console.WriteLine($"[{DateTime.Now}] Deleted {oldObjectName}");
       }
       catch (Exception ex)
       {
           Console.Error.WriteLine($"Error renaming file: {ex.Message}");
       }
   }

   static async Task Main()
   {
       Console.WriteLine("MinIO Rename Loop Started... Press Ctrl+C to stop.");
       int iteration = 0;
       CancellationTokenSource cts = new CancellationTokenSource();

       
       while (!cts.Token.IsCancellationRequested)
       {
           string oldFileName = $"SGW33_b03266502_{iteration}.dat";
           string newFileName = $"SGW33_b03266502_{iteration+1}.dat";

           await RenameFileAsync(oldFileName, newFileName, cts.Token);

           iteration++;
           await Task.Delay(500, cts.Token); 
       }
   }
}

During the execution of the application, I check the Task Manager and see that the number of descriptors for my application keeps growing endlessly. Screenshot:

enter image description here

In my large application, this causes an unmanaged memory leak. There might be a bug in the implementations of the minioClient.CopyObjectAsync() or minioClient.RemoveObjectAsync() functions, or perhaps I am using them incorrectly?

Please help.

The only option seems to be to not copy files inside Minio, but I don't really like that.

发布评论

评论列表(0)

  1. 暂无评论