Skip to content

Commit 3867927

Browse files
committed
Remove user configurable stream read limit
This is a fairly low level configuration that we don't foresee many customers using; can be added back in if requested. For now, when marking, we set the read limit to previous default of 128K.
1 parent 28a5f48 commit 3867927

File tree

10 files changed

+25
-66
lines changed

10 files changed

+25
-66
lines changed

core/auth/src/main/java/software/amazon/awssdk/auth/signer/AwsS3V4Signer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
3434
import software.amazon.awssdk.http.SdkHttpFullRequest;
3535
import software.amazon.awssdk.utils.BinaryUtils;
36+
import software.amazon.awssdk.utils.IoUtils;
3637

3738
/**
3839
* AWS4 signer implementation for AWS S3
@@ -242,7 +243,7 @@ private static long getContentLength(SdkHttpFullRequest.Builder requestBuilder)
242243
long contentLength = 0;
243244
byte[] tmp = new byte[4096];
244245
int read;
245-
content.mark(getReadLimit());
246+
IoUtils.markStreamWithMaxReadLimit(content);
246247
while ((read = content.read(tmp)) != -1) {
247248
contentLength += read;
248249
}

core/auth/src/main/java/software/amazon/awssdk/auth/signer/internal/AbstractAws4Signer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import software.amazon.awssdk.core.signer.Presigner;
4040
import software.amazon.awssdk.http.SdkHttpFullRequest;
4141
import software.amazon.awssdk.utils.BinaryUtils;
42+
import software.amazon.awssdk.utils.IoUtils;
4243
import software.amazon.awssdk.utils.Logger;
4344
import software.amazon.awssdk.utils.http.SdkHttpUtils;
4445

@@ -146,7 +147,7 @@ protected void addSessionCredentials(SdkHttpFullRequest.Builder mutableRequest,
146147
*/
147148
protected String calculateContentHash(SdkHttpFullRequest.Builder mutableRequest, T signerParams) {
148149
InputStream payloadStream = getBinaryRequestPayloadStream(mutableRequest.content());
149-
payloadStream.mark(getReadLimit());
150+
IoUtils.markStreamWithMaxReadLimit(payloadStream);
150151
String contentSha256 = BinaryUtils.toHex(hash(payloadStream));
151152
try {
152153
payloadStream.reset();

core/auth/src/main/java/software/amazon/awssdk/auth/signer/internal/AbstractAwsSigner.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@
2929
import java.util.TreeMap;
3030
import javax.crypto.Mac;
3131
import javax.crypto.spec.SecretKeySpec;
32-
import software.amazon.awssdk.annotations.ReviewBeforeRelease;
3332
import software.amazon.awssdk.annotations.SdkInternalApi;
3433
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
3534
import software.amazon.awssdk.auth.credentials.AwsCredentials;
3635
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
37-
import software.amazon.awssdk.core.RequestOption;
3836
import software.amazon.awssdk.core.exception.SdkClientException;
3937
import software.amazon.awssdk.core.io.SdkDigestInputStream;
4038
import software.amazon.awssdk.core.signer.Signer;
@@ -244,12 +242,6 @@ protected String getCanonicalizedQueryString(Map<String, List<String>> parameter
244242
return SdkHttpUtils.flattenQueryParameters(sorted).orElse("");
245243
}
246244

247-
@ReviewBeforeRelease("Do we still want to make read limit user-configurable as in V1?")
248-
protected static int getReadLimit() {
249-
return RequestOption.DEFAULT_STREAM_BUFFER_SIZE;
250-
251-
}
252-
253245
protected InputStream getBinaryRequestPayloadStream(InputStream stream) {
254246
try {
255247
if (stream == null) {

core/sdk-core/src/main/java/software/amazon/awssdk/core/RequestOption.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,5 @@
2222
*/
2323
@SdkProtectedApi
2424
public final class RequestOption {
25-
public static final int DEFAULT_STREAM_BUFFER_SIZE = (1 << 17) + 1;
26-
2725
private RequestOption() {}
2826
}

core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/http/async/SimpleHttpContentPublisher.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@
2121
import java.util.Optional;
2222
import org.reactivestreams.Subscriber;
2323
import org.reactivestreams.Subscription;
24-
import software.amazon.awssdk.annotations.ReviewBeforeRelease;
2524
import software.amazon.awssdk.annotations.SdkInternalApi;
26-
import software.amazon.awssdk.core.RequestOption;
27-
import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
2825
import software.amazon.awssdk.http.SdkHttpFullRequest;
2926
import software.amazon.awssdk.http.async.SdkHttpContentPublisher;
3027
import software.amazon.awssdk.utils.IoUtils;
@@ -39,10 +36,10 @@ public final class SimpleHttpContentPublisher implements SdkHttpContentPublisher
3936
private final byte[] content;
4037
private final int length;
4138

42-
public SimpleHttpContentPublisher(SdkHttpFullRequest request, ExecutionAttributes executionAttributes) {
39+
public SimpleHttpContentPublisher(SdkHttpFullRequest request) {
4340
this.content = request.content().map(content -> {
4441
try {
45-
content.mark(getReadLimit(executionAttributes));
42+
IoUtils.markStreamWithMaxReadLimit(content);
4643
return invokeSafely(() -> IoUtils.toByteArray(content));
4744
} finally {
4845
invokeSafely(content::reset);
@@ -51,11 +48,6 @@ public SimpleHttpContentPublisher(SdkHttpFullRequest request, ExecutionAttribute
5148
this.length = content.length;
5249
}
5350

54-
@ReviewBeforeRelease("Do we still want to make read limit user-configurable as in V1?")
55-
private int getReadLimit(ExecutionAttributes executionAttributes) {
56-
return RequestOption.DEFAULT_STREAM_BUFFER_SIZE;
57-
}
58-
5951
@Override
6052
public Optional<Long> contentLength() {
6153
return Optional.of(Long.valueOf(length));

core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/http/pipeline/stages/AsyncRetryableStage.java

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
import java.util.concurrent.TimeUnit;
2525
import org.slf4j.Logger;
2626
import org.slf4j.LoggerFactory;
27-
import software.amazon.awssdk.annotations.ReviewBeforeRelease;
2827
import software.amazon.awssdk.annotations.SdkInternalApi;
29-
import software.amazon.awssdk.core.RequestOption;
3028
import software.amazon.awssdk.core.SdkStandardLogger;
3129
import software.amazon.awssdk.core.client.config.SdkClientOption;
3230
import software.amazon.awssdk.core.exception.NonRetryableException;
@@ -44,6 +42,7 @@
4442
import software.amazon.awssdk.core.retry.RetryUtils;
4543
import software.amazon.awssdk.http.SdkHttpFullRequest;
4644
import software.amazon.awssdk.http.SdkHttpFullResponse;
45+
import software.amazon.awssdk.utils.IoUtils;
4746

4847
/**
4948
* Wrapper around the pipeline for a single request to provide retry functionality.
@@ -200,30 +199,12 @@ private CompletableFuture<Response<OutputT>> doExecute() throws Exception {
200199
request.content().ifPresent(AsyncRetryableStage::resetRequestInputStream);
201200
}
202201

203-
request.content().ifPresent(this::markInputStream);
202+
request.content().ifPresent(IoUtils::markStreamWithMaxReadLimit);
204203

205204
SdkStandardLogger.REQUEST_LOGGER.debug(() -> (retryHandler.isRetry() ? "Retrying " : "Sending ") +
206205
"Request: " + request);
207206

208207
return requestPipeline.execute(retryHandler.addRetryInfoHeader(request, requestCount), context);
209208
}
210-
211-
/**
212-
* Mark the input stream at the current position to allow a reset on retries.
213-
*/
214-
private void markInputStream(InputStream originalContent) {
215-
if (originalContent.markSupported()) {
216-
originalContent.mark(readLimit());
217-
}
218-
}
219-
220-
/**
221-
* @return Allowed read limit that we can mark request input stream. If we read past this limit we cannot reset the stream
222-
* so we cannot retry the request.
223-
*/
224-
@ReviewBeforeRelease("Do we still want to make read limit user-configurable as in V1?")
225-
private int readLimit() {
226-
return RequestOption.DEFAULT_STREAM_BUFFER_SIZE;
227-
}
228209
}
229210
}

core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/http/pipeline/stages/MakeAsyncHttpRequestStage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private CompletableFuture<Response<OutputT>> executeHttpRequest(SdkHttpFullReque
9595
final ResponseHandler handler = new ResponseHandler(responseHandler.prepare(), errorResponseFuture);
9696

9797
SdkHttpContentPublisher requestProvider = context.requestProvider() == null
98-
? new SimpleHttpContentPublisher(request, context.executionAttributes())
98+
? new SimpleHttpContentPublisher(request)
9999
: context.requestProvider();
100100
// Set content length if it hasn't been set already.
101101
SdkHttpFullRequest requestWithContentLength = getRequestWithContentLength(request, requestProvider);

core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/http/pipeline/stages/RetryableStage.java

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
import java.io.InputStream;
2020
import java.time.Duration;
2121
import java.util.concurrent.TimeUnit;
22-
import software.amazon.awssdk.annotations.ReviewBeforeRelease;
22+
2323
import software.amazon.awssdk.annotations.SdkInternalApi;
24-
import software.amazon.awssdk.core.RequestOption;
2524
import software.amazon.awssdk.core.SdkStandardLogger;
2625
import software.amazon.awssdk.core.client.config.SdkClientOption;
2726
import software.amazon.awssdk.core.exception.ResetException;
@@ -39,6 +38,7 @@
3938
import software.amazon.awssdk.core.retry.RetryPolicy;
4039
import software.amazon.awssdk.core.retry.RetryUtils;
4140
import software.amazon.awssdk.http.SdkHttpFullRequest;
41+
import software.amazon.awssdk.utils.IoUtils;
4242
import software.amazon.awssdk.utils.Logger;
4343

4444
/**
@@ -131,7 +131,7 @@ private Response<OutputT> doExecute() throws Exception {
131131
doPauseBeforeRetry();
132132
}
133133

134-
request.content().ifPresent(this::markInputStream);
134+
request.content().ifPresent(IoUtils::markStreamWithMaxReadLimit);
135135

136136
SdkStandardLogger.REQUEST_LOGGER.debug(() -> (retryHandler.isRetry() ? "Retrying " : "Sending ") + "Request: " +
137137
request);
@@ -173,24 +173,6 @@ private SdkException handleThrownException(Exception e) {
173173
return sdkClientException;
174174
}
175175

176-
/**
177-
* Mark the input stream at the current position to allow a reset on retries.
178-
*/
179-
private void markInputStream(InputStream originalContent) {
180-
if (originalContent.markSupported()) {
181-
originalContent.mark(readLimit());
182-
}
183-
}
184-
185-
/**
186-
* @return Allowed read limit that we can mark request input stream. If we read past this limit we cannot reset the stream
187-
* so we cannot retry the request.
188-
*/
189-
@ReviewBeforeRelease("Do we still want to make read limit user-configurable as in V1?")
190-
private int readLimit() {
191-
return RequestOption.DEFAULT_STREAM_BUFFER_SIZE;
192-
}
193-
194176
/**
195177
* Sleep for a period of time on failed request to avoid flooding a service with retries.
196178
*/

core/sdk-core/src/test/java/software/amazon/awssdk/core/internal/http/async/SimpleRequestProviderTckTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public SimpleRequestProviderTckTest() {
2020

2121
@Override
2222
public Publisher<ByteBuffer> createPublisher(long l) {
23-
return new SimpleHttpContentPublisher(makeFullRequest(), new ExecutionAttributes());
23+
return new SimpleHttpContentPublisher(makeFullRequest());
2424
}
2525

2626
@Override

utils/src/main/java/software/amazon/awssdk/utils/IoUtils.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,16 @@ public static void drainInputStream(InputStream in) {
124124
// Stream may be self closed by HTTP client so we ignore any failures.
125125
}
126126
}
127+
128+
/**
129+
* If the stream supports marking, marks the stream at the current position with a {@code readLimit} value of
130+
* 128 KiB.
131+
*
132+
* @param s The stream.
133+
*/
134+
public static void markStreamWithMaxReadLimit(InputStream s) {
135+
if (s.markSupported()) {
136+
s.mark(1 << 17);
137+
}
138+
}
127139
}

0 commit comments

Comments
 (0)