Skip to content

PutObjectAsync returns status code 0 when MinIO service is down, without throwing any exception #1318

@jiyi27

Description

@jiyi27

Edited

After downgrading to version 6.0.0, the issue was resolved — the system correctly throws a "connection refused" exception when the MinIO service is not running.

Is this a bug, or am I using it incorrectly?(; ̄Д ̄)


Original

When the MinIO service is down, the SDK method PutObjectAsync does not throw an exception as expected. Instead, it returns a PutObjectResponse object where the ResponseStatusCode is 0, and no errors are exposed to the user. This leads to false assumptions that the upload was successful.

    public async Task<System.Net.HttpStatusCode> UploadFileAsync(
        string bucketName, 
        string objectKey,
        IFormFile file,
        string contentType = "application/octet-stream")
    {
        try
        {
            using var stream = file.OpenReadStream();
            await _createBucketAsync(bucketName);

            var args = new PutObjectArgs()
                .WithBucket(bucketName)
                .WithObject(objectKey)
                .WithStreamData(stream)
                .WithObjectSize(stream.Length)
                .WithContentType(contentType);
            var result = await _minioClient.PutObjectAsync(args);
            return result.ResponseStatusCode;
        }
        catch(Exception ex)
        {
            Console.Error.WriteLine($"upload failed: {ex.Message}");
            throw;
        }
    }

Somewthere:

  var status = await _minIOService.UploadFileAsync(_minioConfig.NodePublicReadBucket, objectKey, file, mimeType);
  Console.WriteLine($"----- status code: {status} --------");
 // other logic, store info into database

Output:

----- status code: 0 --------

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions