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

Multipart upload exception when calling UploadDirectoryAsync #54

Closed
lpallarestorab opened this issue Jun 14, 2024 · 7 comments
Closed
Labels
bug Something isn't working module/s3-encryption-client p1 This is a high priority issue queued

Comments

@lpallarestorab
Copy link

Describe the bug

I´m trying to upload an entire directory client-sided KMS encrypted. The transfer starts but then the upload raise an exception when reach 5242880 bytes (file is close to 100 MB size).

Expected Behavior

success on uploading directory with big size files inside

Current Behavior

HashStream does not support base streams that are not capable of reading or writing

at Amazon.Runtime.Internal.Util.HashStream.ValidateBaseStream()
at Amazon.Runtime.Internal.Util.HashStream1..ctor(Stream baseStream, Byte[] expectedHash, Int64 expectedLength) at Amazon.Runtime.Internal.Util.MD5Stream..ctor(Stream baseStream, Byte[] expectedHash, Int64 expectedLength) at Amazon.S3.Internal.AmazonS3PostMarshallHandler.SetStreamChecksum(UploadPartRequest uploadPartRequest, IRequest request) at Amazon.S3.Internal.AmazonS3PostMarshallHandler.SetStreamChecksum(AmazonWebServiceRequest originalRequest, IRequest request) at Amazon.S3.Internal.AmazonS3PostMarshallHandler.ProcessPreRequestHandlers(IExecutionContext executionContext) at Amazon.S3.Internal.AmazonS3PostMarshallHandler.PreInvoke(IExecutionContext executionContext) at Amazon.S3.Internal.AmazonS3PostMarshallHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.PipelineHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.BaseEndpointResolver.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.PipelineHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Extensions.S3.Encryption.Internal.UserAgentHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.PipelineHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.Marshaller.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.PipelineHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Extensions.S3.Encryption.Internal.SetupEncryptionHandler.<>n__0[T](IExecutionContext executionContext) at Amazon.Extensions.S3.Encryption.Internal.SetupEncryptionHandler.<InvokeAsync>d__111.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Amazon.Runtime.Internal.CallbackHandler.d__91.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Amazon.S3.Internal.AmazonS3ExceptionHandler.<InvokeAsync>d__11.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Amazon.Runtime.Internal.ErrorCallbackHandler.d__51.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Amazon.Runtime.Internal.MetricsHandler.<InvokeAsync>d__11.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Amazon.S3.Transfer.Internal.MultipartUploadCommand.d__28.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Amazon.S3.Transfer.Internal.BaseCommand.d__51.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at Amazon.S3.Transfer.Internal.MultipartUploadCommand.<ExecuteAsync>d__27.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Amazon.S3.Transfer.Internal.BaseCommand.<ExecuteCommandAsync>d__7.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Amazon.S3.Transfer.Internal.BaseCommand.<WhenAllOrFirstExceptionAsync>d__6.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at Amazon.S3.Transfer.Internal.UploadDirectoryCommand.<ExecuteAsync>d__15.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at AWSTools.S3.<TransferUtilityUploadFullDirectoryAsync>d__35.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at RespaldosAWS.BL.RespaldosHandler.d__3.MoveNext() in F:\Proyectos\2023\RespaldosAWS\RespaldosAWS.BL\RespaldosHandler.cs:line 104

Reproduction Steps

try to upload a directory with big size file inside

public async Task UploadEncryptedFullDirectoryAsync(
string filePath, DirectoryUploadTracker uploadTracker, string keyPrefix = null)
{
if (String.IsNullOrWhiteSpace(keyPrefix))
keyPrefix = Path.GetFileName(filePath);

 var uploadRequest = new TransferUtilityUploadDirectoryRequest
 {
     BucketName = Bucket,
     KeyPrefix = keyPrefix,
     Directory = filePath,
     StorageClass = StorageClass
 };

 uploadRequest.UploadDirectoryProgressEvent += new EventHandler<UploadDirectoryProgressArgs>(uploadTracker);

 using (AmazonS3EncryptionClientV2 s3EncryptionClient  = new 
 AmazonS3EncryptionClientV2(S3CryptoConfigurationV2, EncryptionMaterialsV2))
 {
     var transferUtil = new TransferUtility(s3EncryptionClient));
     await transferUtil.UploadDirectoryAsync(uploadRequest);
 }
 return true;

}

Possible Solution

No response

Additional Information/Context

When using not encrypted S3Client works perfectly

AWS .NET SDK and/or Package version used

AWSSDK.Core 3.7.304.16
AWSSDK.S3 3.7.309.4

Targeted .NET Platform

.NET 4.8.1

Operating System and version

Windows 11 Pro 23H2

@lpallarestorab lpallarestorab added the bug Something isn't working label Jun 14, 2024
@bhoradc
Copy link

bhoradc commented Jun 14, 2024

Hello @lpallarestorab,

Thank you for reporting this issue. Can you kindly confirm which package version of Amazon.Extensions.S3.Encryption are you using in your application?

Regards,
Chaitanya

@bhoradc bhoradc added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jun 14, 2024
@lpallarestorab
Copy link
Author

Yes, it is 2.1.1

@bhoradc bhoradc added needs-reproduction This issue needs reproduction. and removed response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Jun 14, 2024
@bhoradc
Copy link

bhoradc commented Jun 26, 2024

Hi @lpallarestorab,

Using below code sample I am able to reproduce the error - HashStream does not support base streams that are not capable of reading or writing.

static async Task Main(string[] args)
{
    Amazon.AWSConfigs.LoggingConfig.LogResponses = Amazon.ResponseLoggingOption.Always;
    Amazon.AWSConfigs.LoggingConfig.LogTo = Amazon.LoggingOptions.Console;
    Amazon.AWSConfigs.AddTraceListener("Amazon", new System.Diagnostics.ConsoleTraceListener());

    await UploadEncryptedFullDirectoryAsync(@"C:\**\download", null);
}
public static async Task UploadEncryptedFullDirectoryAsync(string filePath, string keyPrefix = null)
{
    if (String.IsNullOrWhiteSpace(keyPrefix))
        keyPrefix = Path.GetFileName(filePath);

    var uploadRequest = new TransferUtilityUploadDirectoryRequest
    {
        BucketName = "<<bucket_name>>",
        KeyPrefix = keyPrefix,
        Directory = filePath,
        StorageClass = S3StorageClass.Standard
    };

    var S3CryptoConfigurationV2 = new AmazonS3CryptoConfigurationV2(SecurityProfile.V2);
    var encryptionContext = new Dictionary<string, string>();
    var EncryptionMaterialsV2 =
        new EncryptionMaterialsV2("<<KMS_Id>>", KmsType.KmsContext, encryptionContext);

    using (AmazonS3EncryptionClientV2 s3EncryptionClient = new
        AmazonS3EncryptionClientV2(S3CryptoConfigurationV2, EncryptionMaterialsV2))
    {
        var transferUtil = new TransferUtility(s3EncryptionClient);
        await transferUtil.UploadDirectoryAsync(uploadRequest);
    }
}

Mentioned error is thrown when the object size >= 16 MB (Multipart upload).

I will review this with the .NET SDK team to further investigate it.

Regards,
Chaitanya

@bhoradc bhoradc added needs-review p1 This is a high priority issue queued and removed needs-reproduction This issue needs reproduction. needs-review labels Jun 26, 2024
@bhoradc bhoradc removed their assignment Jul 22, 2024
@lpallarestorab
Copy link
Author

Any updates for this problem??

@normj
Copy link
Member

normj commented Aug 23, 2024

Thanks for reporting the issue. I put out a PR to address the issue: #56

normj added a commit that referenced this issue Aug 27, 2024
normj added a commit that referenced this issue Aug 29, 2024
@normj
Copy link
Member

normj commented Sep 3, 2024

The PR has been released as part of version 2.1.2. Thanks again for reporting the issue.

@normj normj closed this as completed Sep 3, 2024
Copy link

github-actions bot commented Sep 3, 2024

⚠️COMMENT VISIBILITY WARNING⚠️

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 Something isn't working module/s3-encryption-client p1 This is a high priority issue queued
Projects
None yet
Development

No branches or pull requests

3 participants