Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public final class AwsCrtHttpClient extends AwsCrtHttpClientBase implements SdkH
private AwsCrtHttpClient(DefaultBuilder builder, AttributeMap config) {
super(builder, config);
if (this.protocol == Protocol.HTTP2) {
throw new UnsupportedOperationException("HTTP/2 is not supported in sync client. Use AwsCrtAsyncHttpClient instead.");
throw new UnsupportedOperationException(
"HTTP/2 is not supported for sync HTTP clients. Either use HTTP/1.1 (the default) or use an async "
+ "HTTP client (e.g., AwsCrtAsyncHttpClient).");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@
private final HttpProxyOptions proxyOptions;
private final HttpMonitoringOptions monitoringOptions;
private final long maxConnectionIdleInMilliseconds;
private final int maxConnectionsPerEndpoint;
private final int maxStreamsPerEndpoint;
private final long connectionAcquisitionTimeout;
private final TlsContextOptions tlsContextOptions;

Check warning on line 74 in http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/AwsCrtHttpClientBase.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused "tlsContextOptions" private field.

See more on https://sonarcloud.io/project/issues?id=aws_aws-sdk-java-v2&issues=AZ0dpBwJueBB4U5r7qlF&open=AZ0dpBwJueBB4U5r7qlF&pullRequest=6812
private boolean isClosed = false;

AwsCrtHttpClientBase(AwsCrtClientBuilderBase builder, AttributeMap config) {
Expand All @@ -95,7 +95,7 @@
this.tlsContext = registerOwnedResource(clientTlsContext);
this.readBufferSize = builder.getReadBufferSizeInBytes() == null ?
DEFAULT_STREAM_WINDOW_SIZE : builder.getReadBufferSizeInBytes();
this.maxConnectionsPerEndpoint = config.get(SdkHttpConfigurationOption.MAX_CONNECTIONS);
this.maxStreamsPerEndpoint = config.get(SdkHttpConfigurationOption.MAX_CONNECTIONS);
this.monitoringOptions = resolveHttpMonitoringOptions(builder.getConnectionHealthConfiguration()).orElse(null);
this.maxConnectionIdleInMilliseconds = config.get(SdkHttpConfigurationOption.CONNECTION_MAX_IDLE_TIMEOUT).toMillis();
this.connectionAcquisitionTimeout = config.get(SdkHttpConfigurationOption.CONNECTION_ACQUIRE_TIMEOUT).toMillis();
Expand All @@ -121,7 +121,7 @@
}

private HttpStreamManager createConnectionPool(URI uri) {
log.debug(() -> "Creating ConnectionPool for: URI:" + uri + ", MaxConns: " + maxConnectionsPerEndpoint);
log.debug(() -> "Creating ConnectionPool for: URI:" + uri + ", MaxConns: " + maxStreamsPerEndpoint+ ", MaxStreams: " + maxStreamsPerEndpoint);

boolean isHttps = "https".equalsIgnoreCase(uri.getScheme());
TlsContext poolTlsContext = isHttps ? tlsContext : null;
Expand All @@ -132,7 +132,7 @@
.withTlsContext(poolTlsContext)
.withUri(uri)
.withWindowSize(readBufferSize)
.withMaxConnections(maxConnectionsPerEndpoint)
.withMaxConnections(maxStreamsPerEndpoint)
.withManualWindowManagement(true)
.withProxyOptions(proxyOptions)
.withMonitoringOptions(monitoringOptions)
Expand All @@ -144,6 +144,7 @@

if (protocol == Protocol.HTTP2) {
Http2StreamManagerOptions h2Options = new Http2StreamManagerOptions()
.withMaxConcurrentStreams(maxStreamsPerEndpoint)
.withConnectionManagerOptions(h1Options);

if (!isHttps) {
Expand Down Expand Up @@ -180,7 +181,7 @@
throw new IllegalStateException("Client is closed. No more requests can be made with this client.");
}

HttpStreamManager connPool = connectionPools.computeIfAbsent(uri, this::createConnectionPool);

Check warning on line 184 in http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/AwsCrtHttpClientBase.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Immediately return this expression instead of assigning it to the temporary variable "connPool".

See more on https://sonarcloud.io/project/issues?id=aws_aws-sdk-java-v2&issues=AZ0dpBwJueBB4U5r7qlE&open=AZ0dpBwJueBB4U5r7qlE&pullRequest=6812
return connPool;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import java.util.concurrent.CompletionException;
import javax.net.ssl.SSLHandshakeException;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.crt.CRT;
import software.amazon.awssdk.crt.CrtRuntimeException;
import software.amazon.awssdk.crt.http.HttpClientConnection;
import software.amazon.awssdk.crt.http.HttpException;
import software.amazon.awssdk.crt.http.HttpManagerMetrics;
import software.amazon.awssdk.crt.http.HttpStreamManager;
Expand All @@ -50,10 +50,7 @@ private CrtUtils() {
public static Throwable wrapWithIoExceptionIfRetryable(HttpException httpException) {
Throwable toThrow = httpException;

// TODO: switch to Crt.awsIsTransientError once https://github.com/awslabs/aws-crt-java/pull/972 is merged
if (HttpClientConnection.isErrorRetryable(httpException)) {
// IOExceptions get retried, and if the CRT says this error is retryable,
// it's semantically an IOException anyway.
if (CRT.awsIsTransientError(httpException.getErrorCode())) {
toThrow = new IOException(httpException);
}
return toThrow;
Expand All @@ -70,8 +67,7 @@ public static Throwable wrapCrtException(Throwable throwable) {
if (httpErrorCode == CRT_TLS_NEGOTIATION_ERROR_CODE) {
return new SSLHandshakeException(httpException.getMessage());
}
// TODO: check with CRT team, could CRT_SOCKET_TIMEOUT be thrown
// from processes other than tcp connect?

if (httpErrorCode == CRT_SOCKET_TIMEOUT) {
return new ConnectException(httpException.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.crt.http.HttpException;
import software.amazon.awssdk.http.Protocol;
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
import software.amazon.awssdk.utils.AttributeMap;
Expand All @@ -62,11 +63,11 @@
/**
* Tests HTTP/2 error scenarios: RST_STREAM and GOAWAY frames.
*/
public class H2ErrorTest {

Check warning on line 66 in http-clients/aws-crt-client/src/test/java/software/amazon/awssdk/http/crt/H2ErrorTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=aws_aws-sdk-java-v2&issues=AZ0dpBuMueBB4U5r7qk-&open=AZ0dpBuMueBB4U5r7qk-&pullRequest=6812
private SdkAsyncHttpClient client;

@BeforeEach
public void setup() {

Check warning on line 70 in http-clients/aws-crt-client/src/test/java/software/amazon/awssdk/http/crt/H2ErrorTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=aws_aws-sdk-java-v2&issues=AZ0dpBuMueBB4U5r7qk5&open=AZ0dpBuMueBB4U5r7qk5&pullRequest=6812
client = AwsCrtAsyncHttpClient.builder()
.buildWithDefaults(AttributeMap.builder()
.put(TRUST_ALL_CERTIFICATES, true)
Expand All @@ -75,21 +76,21 @@
}

@AfterEach
public void teardown() {

Check warning on line 79 in http-clients/aws-crt-client/src/test/java/software/amazon/awssdk/http/crt/H2ErrorTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=aws_aws-sdk-java-v2&issues=AZ0dpBuMueBB4U5r7qk6&open=AZ0dpBuMueBB4U5r7qk6&pullRequest=6812
if (client != null) {
client.close();
}
}

@Test
public void serverSendsRstStream_shouldThrowIOException() throws Exception {
public void serverSendsRstStream_shouldNotThrowIOException() throws Exception {

Check warning on line 86 in http-clients/aws-crt-client/src/test/java/software/amazon/awssdk/http/crt/H2ErrorTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=aws_aws-sdk-java-v2&issues=AZ0dpBuMueBB4U5r7qk7&open=AZ0dpBuMueBB4U5r7qk7&pullRequest=6812
H2ErrorServer server = new H2ErrorServer(ErrorType.RST_STREAM);
server.init();
try {
CompletableFuture<?> request = sendGetRequest(server.port(), client);
assertThatThrownBy(request::join)
.isInstanceOf(CompletionException.class)
.hasCauseInstanceOf(IOException.class)
.hasCauseInstanceOf(HttpException.class)
.hasMessageContaining("RST_STREAM");
} finally {
server.shutdown();
Expand All @@ -97,7 +98,7 @@
}

@Test
public void tcpConnectFailure_shouldThrowIOException() throws Exception {

Check warning on line 101 in http-clients/aws-crt-client/src/test/java/software/amazon/awssdk/http/crt/H2ErrorTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=aws_aws-sdk-java-v2&issues=AZ0dpBuMueBB4U5r7qk8&open=AZ0dpBuMueBB4U5r7qk8&pullRequest=6812
int unusedPort;
try (ServerSocket ss = new ServerSocket(0)) {
unusedPort = ss.getLocalPort();
Expand All @@ -111,7 +112,7 @@
}

@Test
public void serverSendsGoAway_shouldThrowIOException() throws Exception {

Check warning on line 115 in http-clients/aws-crt-client/src/test/java/software/amazon/awssdk/http/crt/H2ErrorTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=aws_aws-sdk-java-v2&issues=AZ0dpBuMueBB4U5r7qk9&open=AZ0dpBuMueBB4U5r7qk9&pullRequest=6812
H2ErrorServer server = new H2ErrorServer(ErrorType.GOAWAY);
server.init();
try {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
<rxjava3.version>3.1.5</rxjava3.version>
<commons-codec.verion>1.17.1</commons-codec.verion>
<jmh.version>1.37</jmh.version>
<awscrt.version>0.43.5</awscrt.version>
<awscrt.version>0.43.9</awscrt.version>

<!--Test dependencies -->
<junit5.version>5.10.3</junit5.version>
Expand Down
Loading