Skip to content

Commit

Permalink
0005017: HTTP timeout is used for both connect and read timeouts; should
Browse files Browse the repository at this point in the history
provide a separate HTTP connect timeout parameter
  • Loading branch information
Philip Marzullo committed Jun 7, 2021
1 parent ac172f8 commit e13b1ce
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
Expand Up @@ -49,7 +49,7 @@ public SymmetricPushClient(String nodeId, String securityToken, String syncUrl)

public void open() {
try {
transport = new HttpOutgoingTransport(new HttpTransportManager(), new URL(buildUrl()), 30000, true, 0, -1, null,
transport = new HttpOutgoingTransport(new HttpTransportManager(), new URL(buildUrl()), 30000, 30000, true, 0, -1, null,
null, false, -1, false);
writer = new ProtocolDataWriter(nodeId, transport.openWriter(), false);
writer.start(batch);
Expand Down
Expand Up @@ -278,6 +278,7 @@ private ParameterConstants() {

public final static String TRANSPORT_HTTP_MANUAL_REDIRECTS_ENABLED = "http.manual.redirects.enabled";
public final static String TRANSPORT_HTTP_TIMEOUT = "http.timeout.ms";
public final static String TRANSPORT_HTTP_CONNECT_TIMEOUT = "http.connect.timeout.ms";
public final static String TRANSPORT_HTTP_PUSH_STREAM_ENABLED = "http.push.stream.output.enabled";
public final static String TRANSPORT_HTTP_PUSH_STREAM_SIZE = "http.push.stream.output.size";
public final static String TRANSPORT_HTTP_USE_COMPRESSION_CLIENT = "http.compression";
Expand Down
Expand Up @@ -68,6 +68,8 @@ public class HttpOutgoingTransport implements IOutgoingWithResponseTransport {
private HttpURLConnection connection;

private int httpTimeout;

private int httpConnectTimeout;

private boolean useCompression;

Expand All @@ -87,13 +89,14 @@ public class HttpOutgoingTransport implements IOutgoingWithResponseTransport {

private Map<String, String> requestProperties;

public HttpOutgoingTransport(HttpTransportManager httpTransportManager, URL url, int httpTimeout, boolean useCompression,
public HttpOutgoingTransport(HttpTransportManager httpTransportManager, URL url, int httpTimeout, int httpConnectTimeout, boolean useCompression,
int compressionStrategy, int compressionLevel, String nodeId,
String securityToken, boolean streamOutputEnabled, int streamOutputSize,
boolean fileUpload) {
this.httpTransportManager = httpTransportManager;
this.url = url;
this.httpTimeout = httpTimeout;
this.httpConnectTimeout = httpConnectTimeout;
this.useCompression = useCompression;
this.compressionLevel = compressionLevel;
this.compressionStrategy = compressionStrategy;
Expand All @@ -104,11 +107,11 @@ public HttpOutgoingTransport(HttpTransportManager httpTransportManager, URL url,
this.fileUpload = fileUpload;
}

public HttpOutgoingTransport(HttpTransportManager httpTransportManager, URL url, int httpTimeout, boolean useCompression,
public HttpOutgoingTransport(HttpTransportManager httpTransportManager, URL url, int httpTimeout, int httpConnectTimeout, boolean useCompression,
int compressionStrategy, int compressionLevel, String nodeId,
String securityToken, boolean streamOutputEnabled, int streamOutputSize,
boolean fileUpload, Map<String, String> requestProperties) {
this(httpTransportManager, url, httpTimeout, useCompression, compressionStrategy, compressionLevel, nodeId, securityToken,
this(httpTransportManager, url, httpTimeout, httpConnectTimeout, useCompression, compressionStrategy, compressionLevel, nodeId, securityToken,
streamOutputEnabled, streamOutputSize, fileUpload);
this.requestProperties = requestProperties;
}
Expand Down Expand Up @@ -201,7 +204,7 @@ private HttpURLConnection requestReservation(String queue) {
try {
connection = httpTransportManager.openConnection(url, nodeId, securityToken);
connection.setUseCaches(false);
connection.setConnectTimeout(httpTimeout);
connection.setConnectTimeout(httpConnectTimeout);
connection.setReadTimeout(httpTimeout);
connection.setRequestMethod("HEAD");
connection.setRequestProperty(WebConstants.CHANNEL_QUEUE, queue);
Expand All @@ -223,7 +226,7 @@ public OutputStream openStream() {
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setConnectTimeout(httpTimeout);
connection.setConnectTimeout(httpConnectTimeout);
connection.setReadTimeout(httpTimeout);

if (requestProperties != null) {
Expand Down
Expand Up @@ -143,7 +143,7 @@ protected int sendMessage(URL url, String nodeId, String securityToken, String d
conn.setRequestMethod("POST");
conn.setAllowUserInteraction(false);
conn.setDoOutput(true);
conn.setConnectTimeout(getHttpTimeOutInMs());
conn.setConnectTimeout(getHttpConnectTimeOutInMs());
conn.setReadTimeout(getHttpTimeOutInMs());
try(OutputStream os = conn.getOutputStream()) {
writeMessage(os, data);
Expand Down Expand Up @@ -214,6 +214,10 @@ public boolean isOutputStreamEnabled() {
public int getHttpTimeOutInMs() {
return engine.getParameterService().getInt(ParameterConstants.TRANSPORT_HTTP_TIMEOUT);
}

public int getHttpConnectTimeOutInMs() {
return engine.getParameterService().getInt(ParameterConstants.TRANSPORT_HTTP_CONNECT_TIMEOUT);
}

public boolean isUseCompression(Node targetNode) {
// if the node is local, no need to use compression
Expand Down Expand Up @@ -268,23 +272,23 @@ public IOutgoingWithResponseTransport getPushTransport(Node remote, Node local,
String securityToken, Map<String, String> requestProperties,
String registrationUrl) throws IOException {
URL url = new URL(buildURL("push", remote, local, securityToken, registrationUrl));
return new HttpOutgoingTransport(this, url, getHttpTimeOutInMs(), isUseCompression(remote),
return new HttpOutgoingTransport(this, url, getHttpTimeOutInMs(), getHttpConnectTimeOutInMs(), isUseCompression(remote),
getCompressionStrategy(), getCompressionLevel(), local.getNodeId(),
securityToken, isOutputStreamEnabled(), getOutputStreamSize(), false, requestProperties);
}

public IOutgoingWithResponseTransport getPushTransport(Node remote, Node local,
String securityToken, String registrationUrl) throws IOException {
URL url = new URL(buildURL("push", remote, local, securityToken, registrationUrl));
return new HttpOutgoingTransport(this, url, getHttpTimeOutInMs(), isUseCompression(remote),
return new HttpOutgoingTransport(this, url, getHttpTimeOutInMs(), getHttpConnectTimeOutInMs(), isUseCompression(remote),
getCompressionStrategy(), getCompressionLevel(), local.getNodeId(),
securityToken, isOutputStreamEnabled(), getOutputStreamSize(), false);
}

public IOutgoingWithResponseTransport getFilePushTransport(Node remote, Node local,
String securityToken, String registrationUrl) throws IOException {
URL url = new URL(buildURL("filesync/push", remote, local, securityToken, registrationUrl));
return new HttpOutgoingTransport(this, url, getHttpTimeOutInMs(), isUseCompression(remote),
return new HttpOutgoingTransport(this, url, getHttpTimeOutInMs(), getHttpConnectTimeOutInMs(), isUseCompression(remote),
getCompressionStrategy(), getCompressionLevel(), local.getNodeId(),
securityToken, isOutputStreamEnabled(), getOutputStreamSize(), true);
}
Expand All @@ -308,7 +312,7 @@ public IOutgoingWithResponseTransport getBandwidthPushTransport(Node remote, Nod
Map<String, String> requestProperties, String registrationUrl) throws IOException
{
URL url = new URL(resolveURL(remote.getSyncUrl(), registrationUrl) + "/" + "bandwidth?direction=push");
return new HttpOutgoingTransport(this, url, getHttpTimeOutInMs(), isUseCompression(remote),
return new HttpOutgoingTransport(this, url, getHttpTimeOutInMs(), getHttpConnectTimeOutInMs(), isUseCompression(remote),
getCompressionStrategy(), getCompressionLevel(), local.getNodeId(),
securityToken, isOutputStreamEnabled(), getOutputStreamSize(), false, requestProperties);
}
Expand All @@ -335,7 +339,7 @@ public static String buildRegistrationUrl(String baseUrl, Node node) throws IOEx
protected HttpURLConnection createGetConnectionFor(URL url, String nodeId, String securityToken) throws IOException {
HttpURLConnection conn = openConnection(url, nodeId, securityToken);
conn.setRequestProperty("accept-encoding", "gzip");
conn.setConnectTimeout(getHttpTimeOutInMs());
conn.setConnectTimeout(getHttpConnectTimeOutInMs());
conn.setReadTimeout(getHttpTimeOutInMs());
conn.setRequestMethod("GET");
return conn;
Expand Down
Expand Up @@ -329,13 +329,20 @@ send.ack.keepalive.ms=30000
# Type: integer
time.between.ack.retries.ms=5000

# Sets both the connection and read timeout on the internal HttpUrlConnection
# Sets the read timeout on the internal HttpUrlConnection
#
# DatabaseOverridable: true
# Tags: transport
# Type: integer
http.timeout.ms=90000

# Sets the connection timeout on the internal HttpUrlConnection
#
# DatabaseOverridable: true
# Tags: transport
# Type: integer
http.connect.timeout.ms=90000

# Whether or not to use compression over HTTP connections.
# Currently, this setting only affects the push connection of the source node.
# Compression on a pull is enabled using a filter in the web.xml for the PullServlet.
Expand Down

0 comments on commit e13b1ce

Please sign in to comment.