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

AmazonS3 PutObjectAsync is uploading object, but throws "AmazonS3Exception" after hanging for some time #3653

Closed
1 task done
MartinDybdahlM opened this issue Feb 14, 2025 · 4 comments
Labels
bug This issue is a bug. p2 This is a standard priority issue response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. s3

Comments

@MartinDybdahlM
Copy link

Describe the bug

We've recently updated the AWSSDK.S3 NuGet package from version 3.7.310.1 to version 3.7.413, but this causes the PutObjectAsync method to hang for some time and then throw an AmazonS3Exception with message Error making request with Error Code InternalServerError and Http Status Code InternalServerError. No further error information was returned by the service.

We can see the object are uploaded to the S3 bucket.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

The files are uploaded and the method is returning a Task<PutObjectResponse>

Current Behavior

The files are uploaded and the method is hanging for a long time, and then throws an AmazonS3Exception with message Error making request with Error Code InternalServerError and Http Status Code InternalServerError. No further error information was returned by the service.

Reproduction Steps

using Amazon.S3;
using Amazon.S3.Model;
using Microsoft.AspNetCore.Mvc;

namespace Backend.Controllers.ImageController;

[Route("api/[controller]")]
public class ImageController : ControllerBase
{
    private readonly IAmazonS3 _s3Client;

    public ImageController(IAmazonS3 s3Client)
    {
        _s3Client = s3Client;
    }

    public class UploadImageDto
    {
        public required IFormFile Image { get; set; }
    }

    [HttpPost("upload-image")]
    public async Task<ActionResult> UploadImage([FromForm] UploadImageDto dto)
    {
        using var memoryStream = new MemoryStream();
        await dto.Image.CopyToAsync(memoryStream);

        var request = new PutObjectRequest
        {
            BucketName = "my-bucket",
            Key = "my-folder/my-image.jpeg",
            ContentType = "image/jpeg",
            InputStream = memoryStream,
        };

        await _s3Client.PutObjectAsync(request);

        return Ok();
    }
}

Possible Solution

No response

Additional Information/Context

Our workaround for now is to use AWSSDK.S3 3.7.310.1

AWS .NET SDK and/or Package version used

AWSSDK.S3 3.7.413

Targeted .NET Platform

.NET 8

Operating System and version

OSX Sequoia 15.3

@MartinDybdahlM MartinDybdahlM added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 14, 2025
@github-actions github-actions bot added the potential-regression Marking this issue as a potential regression to be checked by team member label Feb 14, 2025
@dscpinheiro
Copy link
Contributor

Just to confirm, are you using actual S3 or a 3rd party implementation?

We made a change last month (#3610) so that the SDK automatically calculates checksums when objects are uploaded (but unfortunately some 3rd party implementations do not support this functionality yet).

If it’s S3, we need more details (which region, what does the image input look like, etc…)

@dscpinheiro dscpinheiro added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Feb 14, 2025
@dscpinheiro
Copy link
Contributor

dscpinheiro commented Feb 14, 2025

Here's what I get when trying your example targeting a bucket in us-west-2 (the PutObject call succeeds without hanging):

AWSSDKUtils 36|2025-02-14T07:39:10.484Z|DEBUG|Single encoded /my-folder/my-image.jpeg with endpoint https://dspin-test-accelerate.s3.us-west-2.amazonaws.com/ for canonicalization: /my-folder/my-image.jpeg
AmazonS3Client 37|2025-02-14T07:39:11.284Z|DEBUG|Received response (truncated to 1024 bytes): []
AmazonS3Client 38|2025-02-14T07:39:11.292Z|INFO|Request metrics: 
    AsyncCall = True;
    CanonicalRequest = 
        PUT
        /my-folder/my-image.jpeg

        content-length:61762
        content-type:image/jpeg
        host:dspin-test-accelerate.s3.us-west-2.amazonaws.com
        user-agent:aws-sdk-dotnet-coreclr/3.7.414.5 ua/2.0 os/windows#10.0.22631.0 md/ARCH#X64 lang/.NET_Core#8.0.13 md/aws-sdk-dotnet-core#3.7.402.1 api/S3#3.7.414.5 cfg/retry-mode#legacy md/ClientAsync cfg/init-coll#1 m/U,Z,b
        x-amz-content-sha256:STREAMING-AWS4-HMAC-SHA256-PAYLOAD-TRAILER
        x-amz-date:20250214T123910Z
        x-amz-decoded-content-length:61466
        x-amz-sdk-checksum-algorithm:CRC32
        x-amz-trailer:x-amz-checksum-crc32

        content-length;content-type;host;user-agent;x-amz-content-sha256;x-amz-date;x-amz-decoded-content-length;x-amz-sdk-checksum-algorithm;x-amz-trailer
        STREAMING-AWS4-HMAC-SHA256-PAYLOAD-TRAILER
    StringToSign = 
        AWS4-HMAC-SHA256
        20250214T123910Z
        20250214/us-west-2/s3/aws4_request
        d5578d8bc74547258bb05bedd8f4b79d244e92f6a59c2a4ea48a399481eef5d3
    ServiceName = AmazonS3
    ServiceEndpoint = https://dspin-test-accelerate.s3.us-west-2.amazonaws.com/
    MethodName = PutObjectRequest
    AmzId2 = kVuAo5yVtCSKvfANiu01SnVhfrUMru08EU0XnHGiPMDuYtGU0uGVSS9TfQkqMJDuTKkJck4K+818mjseH8JEkQ==
    StatusCode = OK
    BytesProcessed = 0
    AWSRequestID = 8RGBVW1M7GGFBARG
    CredentialsRequestTime = 00:00:00.0009941
    RequestSigningTime = 00:00:00.0222286
    HttpRequestTime = 00:00:00.7575643
    ResponseUnmarshallTime = 00:00:00.0021674
    ResponseProcessingTime = 00:00:00.0231256
    ClientExecuteTime = 00:00:00.8855579

I enabled the debug logging by adding these lines to my Program.cs file:

AWSConfigs.LoggingConfig.LogTo = LoggingOptions.Console;
AWSConfigs.LoggingConfig.LogMetricsFormat = LogMetricsFormatOption.Standard;
AWSConfigs.LoggingConfig.LogResponses = ResponseLoggingOption.Always;
AWSConfigs.LoggingConfig.LogMetrics = true;

builder.Services.AddDefaultAWSOptions(builder.Configuration.GetAWSOptions());
builder.Services.AddAWSService<IAmazonS3>();
// etc...

@dscpinheiro dscpinheiro removed the potential-regression Marking this issue as a potential regression to be checked by team member label Feb 14, 2025
@ashishdhingra ashishdhingra added s3 p2 This is a standard priority issue labels Feb 14, 2025
@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Feb 15, 2025
@dscpinheiro dscpinheiro added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Feb 15, 2025
@MartinDybdahlM
Copy link
Author

We are actually using a 3rd party implementation locally (S3-Ninja). I've been trying to recreate it using a real S3 bucket, and it seems to work as expected. So i guess it is related to the 3rd party, as you mention. Sorry about that, i thought the issue was related to this package...

I will replace the S3-Ninja with an actual S3 bucket for local development, so we get closer to a replication of our production environment during development.

Thanks for the quick answers!

Copy link

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p2 This is a standard priority issue response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. s3
Projects
None yet
Development

No branches or pull requests

3 participants