Skip to content

Commit 3d20001

Browse files
authored
Bind response first byte timeout for ConnectionManager (#872)
1 parent 43b66dc commit 3d20001

10 files changed

+37
-15
lines changed

crt/s2n

Submodule s2n updated from 21cefc1 to 4ed4f1a

src/main/java/software/amazon/awssdk/crt/http/HttpClientConnectionManager.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66

77
import java.net.URI;
88
import java.nio.charset.Charset;
9-
import java.util.Queue;
109
import java.util.concurrent.CompletableFuture;
11-
import java.util.concurrent.ConcurrentLinkedQueue;
12-
13-
import software.amazon.awssdk.crt.CRT;
1410
import software.amazon.awssdk.crt.CrtResource;
1511
import software.amazon.awssdk.crt.CrtRuntimeException;
1612
import software.amazon.awssdk.crt.io.ClientBootstrap;
@@ -138,7 +134,8 @@ private HttpClientConnectionManager(HttpClientConnectionManagerOptions options)
138134
monitoringFailureIntervalInSeconds,
139135
expectedHttpVersion.getValue(),
140136
options.getMaxPendingConnectionAcquisitions(),
141-
options.getConnectionAcquisitionTimeoutInMilliseconds()));
137+
options.getConnectionAcquisitionTimeoutInMilliseconds(),
138+
options.getResponseFirstByteTimeoutInMilliseconds()));
142139

143140
/* we don't need to add a reference to socketOptions since it's copied during connection manager construction */
144141
addReferenceTo(clientBootstrap);
@@ -271,7 +268,8 @@ private static native long httpClientConnectionManagerNew(HttpClientConnectionMa
271268
int monitoringFailureIntervalInSeconds,
272269
int expectedProtocol,
273270
long maxPendingConnectionAcquisitions,
274-
long connectionAcquisitionTimeoutInMilliseconds) throws CrtRuntimeException;
271+
long connectionAcquisitionTimeoutInMilliseconds,
272+
long responseFirstByteTimeoutInMilliseconds) throws CrtRuntimeException;
275273

276274
private static native void httpClientConnectionManagerRelease(long conn_manager) throws CrtRuntimeException;
277275

src/main/java/software/amazon/awssdk/crt/http/HttpClientConnectionManagerOptions.java

+23-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
*/
55
package software.amazon.awssdk.crt.http;
66

7-
import java.net.URI;
87
import software.amazon.awssdk.crt.io.ClientBootstrap;
98
import software.amazon.awssdk.crt.io.SocketOptions;
109
import software.amazon.awssdk.crt.io.TlsConnectionOptions;
1110
import software.amazon.awssdk.crt.io.TlsContext;
11+
import java.net.URI;
1212

1313
/**
1414
* Contains all the configuration options for a HttpConnectionPoolManager instance
@@ -35,6 +35,7 @@ public class HttpClientConnectionManagerOptions {
3535
private HttpVersion expectedHttpVersion = HttpVersion.HTTP_1_1;
3636
private long connectionAcquisitionTimeoutInMilliseconds;
3737
private long maxPendingConnectionAcquisitions;
38+
private long responseFirstByteTimeoutInMilliseconds;
3839

3940
private static final String HTTP = "http";
4041
private static final String HTTPS = "https";
@@ -350,6 +351,27 @@ public HttpClientConnectionManagerOptions withMonitoringOptions(HttpMonitoringOp
350351
*/
351352
public HttpMonitoringOptions getMonitoringOptions() { return monitoringOptions; }
352353

354+
/**
355+
* @return the response first byte timeout in milliseconds
356+
*/
357+
public long getResponseFirstByteTimeoutInMilliseconds() {
358+
return responseFirstByteTimeoutInMilliseconds;
359+
}
360+
361+
/**
362+
* Sets the responseFirstByteTimeoutInMilliseconds.
363+
* After a request is fully sent, if the server does not begin responding within N milliseconds,
364+
* then fail with AWS_ERROR_HTTP_RESPONSE_FIRST_BYTE_TIMEOUT.
365+
*
366+
* @param responseFirstByteTimeoutInMilliseconds first byte timeout in milliseconds
367+
* @return this
368+
*/
369+
public HttpClientConnectionManagerOptions withResponseFirstByteTimeoutInMilliseconds(long responseFirstByteTimeoutInMilliseconds) {
370+
this.responseFirstByteTimeoutInMilliseconds = responseFirstByteTimeoutInMilliseconds;
371+
return this;
372+
}
373+
374+
353375
/**
354376
* Validate the connection manager options are valid to use. Throw exceptions if not.
355377
*/

src/native/http_connection_manager.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_http_HttpClientConnectio
117117
jint jni_monitoring_failure_interval_in_seconds,
118118
jint jni_expected_protocol_version,
119119
jlong jni_max_pending_connection_acquisitions,
120-
jlong jni_connection_acquisition_timeout_ms) {
120+
jlong jni_connection_acquisition_timeout_ms,
121+
jlong jni_response_first_byte_timeout_ms) {
121122

122123
(void)jni_class;
123124
(void)jni_expected_protocol_version;
@@ -191,6 +192,7 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_http_HttpClientConnectio
191192
manager_options.max_connection_idle_in_milliseconds = jni_max_connection_idle_in_milliseconds;
192193
manager_options.max_pending_connection_acquisitions = jni_max_pending_connection_acquisitions;
193194
manager_options.connection_acquisition_timeout_ms = jni_connection_acquisition_timeout_ms;
195+
manager_options.response_first_byte_timeout_ms = jni_response_first_byte_timeout_ms;
194196

195197
struct aws_http_connection_monitoring_options monitoring_options;
196198
AWS_ZERO_STRUCT(monitoring_options);

0 commit comments

Comments
 (0)