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

Uploading stream to S3 invoke error "The request body terminated unexpectedly" #3616

Open
1 task done
digitlegacy opened this issue Jan 21, 2025 · 4 comments
Open
1 task done
Assignees
Labels
bug This issue is a bug. p3 This is a minor priority issue response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. s3

Comments

@digitlegacy
Copy link

Describe the bug

Simple upload of stream as follow:
var request = new PutObjectRequest { BucketName = _bucketName, Key = path, InputStream = stream };

It all worked in AWSSDK.S3 version 3.7.411.7 but since version 3.7.412 I keep getting exception with error code 'IncompleteBody':

Amazon.S3.AmazonS3Exception: The request body terminated unexpectedly
---> Amazon.Runtime.Internal.HttpErrorResponseException: Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown.
at Amazon.Runtime.HttpWebRequestMessage.ProcessHttpResponseMessage(HttpResponseMessage responseMessage)
at Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken)
at Amazon.Runtime.Internal.HttpHandler1.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.RedirectHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.Unmarshaller.InvokeAsync[T](IExecutionContext executionContext) at Amazon.S3.Internal.AmazonS3ResponseHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext) --- End of inner exception stack trace --- at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleExceptionStream(IRequestContext requestContext, IWebResponseData httpErrorResponse, HttpErrorResponseException exception, Stream responseStream) at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleExceptionAsync(IExecutionContext executionContext, HttpErrorResponseException exception) at Amazon.Runtime.Internal.ExceptionHandler1.HandleAsync(IExecutionContext executionContext, Exception exception)
at Amazon.Runtime.Internal.ErrorHandler.ProcessExceptionAsync(IExecutionContext executionContext, Exception exception)
at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.Signer.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.S3.Internal.S3Express.S3ExpressPreSigner.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CredentialsRetriever.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.S3.Internal.AmazonS3ExceptionHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.MetricsHandler.InvokeAsync[T](IExecutionContext executionContext)
at DigitalLegacy.Infrastructure.S3.S3FileStorage.UploadFile(String absolutePath, Stream fileStream)

Regression Issue

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

Expected Behavior

The stream should have been uploaded to S3

Current Behavior

I get exceptions indicating the stream was closed before finished uploading

Reproduction Steps

Just try to upload a stream using PutObjectRequest

var request = new PutObjectRequest { BucketName = _bucketName, Key = path, InputStream = stream };

Possible Solution

No response

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

AWSSDK.S3 3.7.412

Targeted .NET Platform

.NET 9

Operating System and version

Windows

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

dscpinheiro commented Jan 21, 2025

Are you using S3 or a 3rd-party implementation? We made a change last week so that the SDK automatically calculates checksums for all PutObject calls: #3610 (here's a similar report from yesterday - where they were using MinIO: #3615)

If this is happening with S3, we'd need more details (what region, what does your input stream 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. potential-regression Marking this issue as a potential regression to be checked by team member labels Jan 21, 2025
@ashishdhingra ashishdhingra added s3 p3 This is a minor priority issue labels Jan 21, 2025
@mhehle
Copy link

mhehle commented Jan 25, 2025

Can confirm this error with multiple different 3rd-party implementations like hetzner and openstack.
Last working version 3.7.411.7

@dscpinheiro
Copy link
Contributor

dscpinheiro commented Jan 25, 2025

Got it, thanks for confirming it's happening for 3rd-party implementations. As mentioned in the announcement I linked earlier, this is a change we made intentionally and there's a config option you can set to disable the checksum calculation for PutObject / UploadPart calls:

var s3Config = new AmazonS3Config
{
    ServiceURL = "your-custom-service-url",
    RequestChecksumCalculation = RequestChecksumCalculation.WHEN_REQUIRED,
};
var s3 = new AmazonS3Client(s3Config);
await s3.PutObjectAsync(...);

This should unblock you, although obviously the ideal solution would be for the 3rd-party implementations to support this new behavior as it's in place for all AWS SDKs - not only .NET (this documentation page from S3 explains how the data integrity works: https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html)

@mhehle
Copy link

mhehle commented Jan 25, 2025

@dscpinheiro thank you for your fast response.
Your suggested configuration change works!

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jan 26, 2025
@dscpinheiro dscpinheiro added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jan 27, 2025
@dscpinheiro dscpinheiro self-assigned this Jan 27, 2025
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. p3 This is a minor 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

4 participants