Skip to content

Commit

Permalink
Adding connection read timeout to prevent indefinite wait (opensearch…
Browse files Browse the repository at this point in the history
…-project#354)

Signed-off-by: Sagar Upadhyaya <sagar.upadhyaya.121@gmail.com>

Signed-off-by: Sagar Upadhyaya <sagar.upadhyaya.121@gmail.com>
  • Loading branch information
sgup432 committed Jan 4, 2023
1 parent d462e20 commit 066cef8
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class PerformanceAnalyzerResourceProvider extends BaseRestHandler {
LogManager.getLogger(PerformanceAnalyzerResourceProvider.class);

private static final int HTTP_CLIENT_CONNECTION_TIMEOUT_MILLIS = 200;
private static final int HTTP_READ_CONNECTON_TIMEOUT_MILLIS = 10000;
private static final String AGENT_PATH = RestConfig.PA_BASE_URI + "/_agent/";
private static final String LEGACY_AGENT_PATH = RestConfig.LEGACY_PA_BASE_URI + "/_agent/";
private static final String DEFAULT_PORT_NUMBER = "9600";
Expand Down Expand Up @@ -202,12 +203,14 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
private HttpURLConnection createHttpsURLConnection(URL url) throws IOException {
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
httpsURLConnection.setConnectTimeout(HTTP_CLIENT_CONNECTION_TIMEOUT_MILLIS);
httpsURLConnection.setReadTimeout(HTTP_READ_CONNECTON_TIMEOUT_MILLIS);
return httpsURLConnection;
}

private HttpURLConnection createHttpURLConnection(URL url) throws IOException {
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setConnectTimeout(HTTP_CLIENT_CONNECTION_TIMEOUT_MILLIS);
httpURLConnection.setReadTimeout(HTTP_READ_CONNECTON_TIMEOUT_MILLIS);
return httpURLConnection;
}

Expand Down

0 comments on commit 066cef8

Please sign in to comment.