Skip to content

Commit

Permalink
Adding connection read timeout to prevent indefinite wait (#354) (#356)
Browse files Browse the repository at this point in the history
Signed-off-by: Sagar Upadhyaya <[email protected]>

Signed-off-by: Sagar Upadhyaya <[email protected]>
(cherry picked from commit 066cef8)

Co-authored-by: Sagar <[email protected]>
  • Loading branch information
opensearch-trigger-bot[bot] and sgup432 authored Jan 9, 2023
1 parent a587fa8 commit 89f109f
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,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 @@ -219,12 +220,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 89f109f

Please sign in to comment.