Skip to content

Fix Trailer based Http Checksum for Async Request body with variable chunk size #3380

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

Merged
merged 6 commits into from
Sep 15, 2022

Conversation

joviegas
Copy link
Contributor

@joviegas joviegas commented Aug 25, 2022

Motivation and Context

Fix Trailer based Http Checksum for Async Request body created from File

Modifications

  • The Non last chunks in ChecksumCalculatingAsyncRequestBody.ChecksumCalculatingSubscriber was not appending the Chunk size and Carriage return to the chunks.

  • The FileAsynRequest Body was not handled , this sends the data in chunks of 16KB, thus the Content-length is updated to consider additional bytes due to size and Carriage return

  • Added ChunkBuffer class that will Buffer the incoming bytes until it reaches buffer_size

  • Added flatMapIterable to wrapped netty stream of data such that we map it to ChunkBuffer
    wrapped.flatMapIterable(this::buffer).subscribe(new ChecksumCalculatingSubscriber(s, sdkChecksum, trailerHeader, totalBytes));

Testing

Screenshots (if appropriate)

  • Integ test with File Async body Greater and less than 16K added both for sync and async.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

License

  • I confirm that this pull request can be released under the Apache 2 license

@joviegas joviegas requested a review from a team as a code owner August 25, 2022 08:37
@joviegas joviegas force-pushed the flexibleChecksumBug branch from e0c75c3 to 42a3d05 Compare August 25, 2022 08:46
@joviegas joviegas force-pushed the flexibleChecksumBug branch from 42a3d05 to f6a7a43 Compare August 25, 2022 15:34
Comment on lines 221 to 223
ByteBuffer checksumAppendedBuffer = ByteBuffer.allocate(contentChunk.remaining());
checksumAppendedBuffer.put(contentChunk);
checksumAppendedBuffer.flip();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the need for this. Why create a copy of contentChunk?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

@joviegas joviegas force-pushed the flexibleChecksumBug branch 5 times, most recently from f3ac7de to ac0e9cf Compare September 4, 2022 23:49
@joviegas joviegas force-pushed the flexibleChecksumBug branch from ac0e9cf to f02605b Compare September 5, 2022 18:18
@joviegas joviegas force-pushed the flexibleChecksumBug branch 4 times, most recently from 9662737 to 423686c Compare September 9, 2022 15:33
@@ -28,12 +28,16 @@
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static software.amazon.awssdk.http.Header.CONTENT_LENGTH;
import static software.amazon.awssdk.http.Header.CONTENT_TYPE;
import static software.amazon.awssdk.testutils.FileUtils.fixedLengthInKbFileWithRandomOrFixedCharacters;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will raise another PR for converting this to Junit5 .

@joviegas joviegas force-pushed the flexibleChecksumBug branch from 423686c to b662515 Compare September 9, 2022 17:40
@@ -41,6 +42,8 @@
@SdkInternalApi
public class ChecksumCalculatingAsyncRequestBody implements AsyncRequestBody {

public static final int DEFAULT_CHUNK_SIZE = 16 * 1024;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of making it a public member in this class, can we create a constant class to put all checksum related chunk size constants?

@joviegas joviegas force-pushed the flexibleChecksumBug branch 3 times, most recently from a16a18b to 1dcd041 Compare September 13, 2022 19:54
@joviegas joviegas changed the title Fix Trailer based Http Checksum for Async Request body created from File Fix Trailer based Http Checksum for Async Request body with variable chunk size Sep 14, 2022

public List<ByteBuffer> getBufferedList() {
if (currentBuffer == null) {
throw new IllegalStateException("");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currentBuffer should never be null, right?

* Class that will buffer incoming BufferBytes of totalBytes length to chunks of bufferSize*
*/
@SdkInternalApi
public final class ChunkBuffer {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, we should probably make this thread safe

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 26 Code Smells

94.5% 94.5% Coverage
1.9% 1.9% Duplication

@sonarqubecloud
Copy link

Please retry analysis of this Pull-Request directly on SonarCloud.

Copy link
Contributor

@zoewangg zoewangg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we trigger the test suites if we haven't already

@joviegas joviegas merged commit 62daf53 into master Sep 15, 2022
@joviegas joviegas deleted the flexibleChecksumBug branch September 19, 2022 18:13
aws-sdk-java-automation added a commit that referenced this pull request Oct 24, 2024
…55c7c4cb3

Pull request: release <- staging/94641a3e-f760-4614-bf42-f4d55c7c4cb3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants