Skip to content

Re Opening Race conditions in S3 upload #6115Β #6940

@radding

Description

@radding

Checkboxes for prior research

Describe the bug

This reopens #6115

I have encountered this issue using the Open Next CDK constructs. I have also found a potential work around for this issue in case it is useful to find a root cause.

The code that causes this issue is this code here: https://github.com/jetbridge/cdk-nextjs/blob/d5c116b0bffb14cc28928c32362946e9aef807b1/src/lambdas/nextjs-bucket-deployment.ts#L296

The solution to work around the bug is: https://github.com/radding/cdk-nextjs/blob/main/src/lambdas/nextjs-bucket-deployment.ts#L299C4-L311C36

As you can see in those two code samples, the work around is moving from uploading content in parallel to uploading content in serial. The await putObjectInputs.reduce(async (acc, params) waits for the previous upload to complete before attempting to upload the next object.

Regression Issue

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

SDK version number

@aws-sdk/[email protected]

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v20.11.0

Reproduction Steps

  1. Have a directory of files of various sizes, some images, some HTML, some Javascript
  2. Execute this code:
const fs = require('fs');

Promise.all(fs.readdirSync(testFolder).map(file => {
  const upload = new Upload({.., params: { Key: file, Body: fs.readFileSync(file), Bucket: <target_bucket> })
  return upload.done();
}));

Observed Behavior

Results in the following error and no upload: XAmzContentSHA256Mismatch: The provided 'x-amz-content-sha256' header does not match what was computed.

Expected Behavior

No error and upload is successful.

Possible Solution

My hypothesis is that there is something sharing memory between upload requests, as switch to serial uploads solves the problem. I suspect the problem is with in the multipart upload code, but I have not had the opportunity to dig in any deeper than this.

Additional Information/Context

This is basically just adding on to #6115

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.investigatingIssue is being investigated and/or work is in progress to resolve the issue.p1This is a high priority issuequeuedThis issues is on the AWS team's backlog

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions