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.