Skip to content

Commit

Permalink
bugfix nginx collect http deadlock error (#1476)
Browse files Browse the repository at this point in the history
Signed-off-by: tomsun28 <tomsun28@outlook.com>
  • Loading branch information
tomsun28 authored Jan 9, 2024
1 parent 0f90e90 commit e9913d7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ public void collect(CollectRep.MetricsData.Builder builder,
}
HttpContext httpContext = createHttpContext(metrics.getHttp());
HttpUriRequest request = createHttpRequest(metrics.getHttp());
try {
CloseableHttpResponse response = CommonHttpClient.getHttpClient()
.execute(request, httpContext);
try (CloseableHttpResponse response = CommonHttpClient.getHttpClient().execute(request, httpContext)) {
int statusCode = response.getStatusLine().getStatusCode();
boolean isSuccessInvoke = checkSuccessInvoke(metrics, statusCode);
log.debug("http response status: {}", statusCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,8 @@ public void collect(CollectRep.MetricsData.Builder builder, long monitorId, Stri

HttpContext httpContext = createHttpContext(metrics.getNginx());
HttpUriRequest request = createHttpRequest(metrics.getNginx());
try {
try (CloseableHttpResponse response = CommonHttpClient.getHttpClient().execute(request, httpContext)){
// 发起http请求,获取响应数据
CloseableHttpResponse response = CommonHttpClient.getHttpClient()
.execute(request, httpContext);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != SUCCESS_CODE) {
builder.setCode(CollectRep.Code.FAIL);
Expand All @@ -105,6 +103,10 @@ public void collect(CollectRep.MetricsData.Builder builder, long monitorId, Stri
log.info(errorMsg);
builder.setCode(CollectRep.Code.FAIL);
builder.setMsg(errorMsg);
} finally {
if (request != null) {
request.abort();
}
}

}
Expand Down

0 comments on commit e9913d7

Please sign in to comment.