Skip to content

Commit

Permalink
Adding connection read timeout to prevent indefinite wait (#354) (#357)
Browse files Browse the repository at this point in the history
Signed-off-by: Sagar Upadhyaya <sagar.upadhyaya.121@gmail.com>

Signed-off-by: Sagar Upadhyaya <sagar.upadhyaya.121@gmail.com>
(cherry picked from commit 066cef8)

Co-authored-by: Sagar <99425694+sgup432@users.noreply.github.com>
  • Loading branch information
opensearch-trigger-bot[bot] and sgup432 committed Jan 9, 2023
1 parent 119fc59 commit d40f521
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 d40f521

Please sign in to comment.