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

Add AsyncRequestBody#fromInputStream(AsyncRequestBodyFromInputStreamC… #4643

Merged
merged 2 commits into from
Oct 30, 2023

Conversation

zoewangg
Copy link
Contributor

@zoewangg zoewangg commented Oct 27, 2023

…onfiguration) to allow users to specify the max read limit on the InputStream

Motivation and Context

Transient network error is not uncommon when customers upload objects of a larger size to S3 and those failed requests would normally succeed upon retry. However, if users use AsyncRequestBodyFromInputStream as the AsyncRequestBody and the stream is larger than the default mark value, the SDK may not be able to retry the request in the event of network issue. This is because the default read limit of the provided inputStream used for mark and reset is 128KB.

java.io.IOException: Resetting to invalid mark

	at java.base/java.io.BufferedInputStream.reset(BufferedInputStream.java:454)

Related to aws/aws-sdk-java#427

Notes:

  • This option is exposed in v1 via RequestClientOptions#setReadLimit. I did not include this in the ReqeustOverrideConfiguration because this only applies to InputStream only.

  • This is technically possible to do in RequestBody, (RequestBody#fromContentProvider), that's why I didn't make the change in RequestBody

Modifications

Add AsyncRequestBody#fromInputStream(AsyncRequestBodyFromInputStreamConfiguration) that allow users to configure max read limit.

Testing

Added unit tests

Screenshots (if appropriate)

Types of changes

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

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

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

@zoewangg zoewangg requested a review from a team as a code owner October 27, 2023 23:31
* should create an {@link AsyncRequestBody} from an {@link InputStream}.
*/
@SdkPublicApi
public final class AsyncRequestBodyFromInputStreamConfiguration implements ToCopyableBuilder<AsyncRequestBodyFromInputStreamConfiguration.Builder,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a bit mouthful, lmk if you have better ideas.

* effect if the stream doesn't support mark and reset.
*
* <p>
* By default, it is 128 KiB.
Copy link
Contributor Author

@zoewangg zoewangg Oct 27, 2023

Choose a reason for hiding this comment

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

Alternatively, we could make it contentLength + 1 so that users don't have to configure it by themselves, however, this would mean it may buffer all the data, so I'm reluctant to make this the default behavior.

…onfiguration) to allow users to specify the max read limit on the InputStream
@zoewangg zoewangg force-pushed the zoewang/allowReadLimitConfiguration branch from dee8d64 to 7c04729 Compare October 27, 2023 23:52
@sonarcloud
Copy link

sonarcloud bot commented Oct 30, 2023

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 9 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@zoewangg zoewangg merged commit f97fd72 into master Oct 30, 2023
14 checks passed
@zoewangg zoewangg deleted the zoewang/allowReadLimitConfiguration branch October 30, 2023 21:33
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.

2 participants