You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2021/02/25 02:05:29 UTC
[skywalking] branch master updated: Fix alarm httpclient connection
leak (#6431)
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git
The following commit(s) were added to refs/heads/master by this push:
new 5b49f8f Fix alarm httpclient connection leak (#6431)
5b49f8f is described below
commit 5b49f8f9fd7aa0095e1922c2e6225948e244b57c
Author: haoyann <10...@qq.com>
AuthorDate: Thu Feb 25 10:05:08 2021 +0800
Fix alarm httpclient connection leak (#6431)
---
CHANGES.md | 1 +
.../oap/server/core/alarm/provider/WebhookCallback.java | 12 +++++++++++-
.../core/alarm/provider/dingtalk/DingtalkHookCallback.java | 12 +++++++++++-
.../core/alarm/provider/feishu/FeishuHookCallback.java | 12 +++++++++++-
.../server/core/alarm/provider/slack/SlackhookCallback.java | 12 +++++++++++-
.../core/alarm/provider/wechat/WechatHookCallback.java | 12 +++++++++++-
6 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index a26d20f..2102ab6 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -29,6 +29,7 @@ Release Notes.
* Fix kubernetes.client.opeanapi.ApiException.
* Remove filename suffix in the meter active file config.
* Introduce log analysis language (LAL).
+* Fix alarm httpclient connection leak.
#### UI
* Update selector scroller to show in all pages.
diff --git a/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/WebhookCallback.java b/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/WebhookCallback.java
index c997d6a..96d8d93 100644
--- a/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/WebhookCallback.java
+++ b/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/WebhookCallback.java
@@ -74,10 +74,11 @@ public class WebhookCallback implements AlarmCallback {
post.setHeader(HttpHeaders.CONTENT_TYPE, HttpHeaderValues.APPLICATION_JSON.toString());
StringEntity entity;
+ CloseableHttpResponse httpResponse = null;
try {
entity = new StringEntity(gson.toJson(alarmMessage), StandardCharsets.UTF_8);
post.setEntity(entity);
- CloseableHttpResponse httpResponse = httpClient.execute(post);
+ httpResponse = httpClient.execute(post);
StatusLine statusLine = httpResponse.getStatusLine();
if (statusLine != null && statusLine.getStatusCode() != HttpStatus.SC_OK) {
log.error("send alarm to " + url + " failure. Response code: " + statusLine.getStatusCode());
@@ -86,6 +87,15 @@ public class WebhookCallback implements AlarmCallback {
log.error("Alarm to JSON error, " + e.getMessage(), e);
} catch (IOException e) {
log.error("send alarm to " + url + " failure.", e);
+ } finally {
+ if (httpResponse != null) {
+ try {
+ httpResponse.close();
+ } catch (IOException e) {
+ log.error(e.getMessage(), e);
+ }
+
+ }
}
});
} finally {
diff --git a/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/dingtalk/DingtalkHookCallback.java b/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/dingtalk/DingtalkHookCallback.java
index 5acc63a..e2ce793 100644
--- a/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/dingtalk/DingtalkHookCallback.java
+++ b/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/dingtalk/DingtalkHookCallback.java
@@ -134,6 +134,7 @@ public class DingtalkHookCallback implements AlarmCallback {
* Send alarm message to remote endpoint
*/
private void sendAlarmMessage(CloseableHttpClient httpClient, String url, String requestBody) {
+ CloseableHttpResponse httpResponse = null;
try {
HttpPost post = new HttpPost(url);
post.setConfig(requestConfig);
@@ -141,7 +142,7 @@ public class DingtalkHookCallback implements AlarmCallback {
post.setHeader(HttpHeaders.CONTENT_TYPE, HttpHeaderValues.APPLICATION_JSON.toString());
StringEntity entity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
post.setEntity(entity);
- CloseableHttpResponse httpResponse = httpClient.execute(post);
+ httpResponse = httpClient.execute(post);
StatusLine statusLine = httpResponse.getStatusLine();
if (statusLine != null && statusLine.getStatusCode() != HttpStatus.SC_OK) {
log.error("send dingtalk alarm to {} failure. Response code: {}, Response content: {}", url, statusLine.getStatusCode(),
@@ -149,6 +150,15 @@ public class DingtalkHookCallback implements AlarmCallback {
}
} catch (Throwable e) {
log.error("send dingtalk alarm to {} failure.", url, e);
+ } finally {
+ if (httpResponse != null) {
+ try {
+ httpResponse.close();
+ } catch (IOException e) {
+ log.error(e.getMessage(), e);
+ }
+
+ }
}
}
}
diff --git a/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/feishu/FeishuHookCallback.java b/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/feishu/FeishuHookCallback.java
index bff3a55..02a9a3a 100644
--- a/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/feishu/FeishuHookCallback.java
+++ b/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/feishu/FeishuHookCallback.java
@@ -153,6 +153,7 @@ public class FeishuHookCallback implements AlarmCallback {
* Send alarm message to remote endpoint
*/
private void sendAlarmMessage(CloseableHttpClient httpClient, String url, String requestBody) {
+ CloseableHttpResponse httpResponse = null;
try {
HttpPost post = new HttpPost(url);
post.setConfig(requestConfig);
@@ -160,7 +161,7 @@ public class FeishuHookCallback implements AlarmCallback {
post.setHeader(HttpHeaders.CONTENT_TYPE, HttpHeaderValues.APPLICATION_JSON.toString());
StringEntity entity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
post.setEntity(entity);
- CloseableHttpResponse httpResponse = httpClient.execute(post);
+ httpResponse = httpClient.execute(post);
StatusLine statusLine = httpResponse.getStatusLine();
if (statusLine != null && statusLine.getStatusCode() != HttpStatus.SC_OK) {
log.error("send feishu alarm to {} failure. Response code: {}, Response content: {}", url, statusLine.getStatusCode(),
@@ -168,6 +169,15 @@ public class FeishuHookCallback implements AlarmCallback {
}
} catch (Throwable e) {
log.error("send feishu alarm to {} failure.", url, e);
+ } finally {
+ if (httpResponse != null) {
+ try {
+ httpResponse.close();
+ } catch (IOException e) {
+ log.error(e.getMessage(), e);
+ }
+
+ }
}
}
}
diff --git a/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/slack/SlackhookCallback.java b/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/slack/SlackhookCallback.java
index 95030a5..c51cbc5 100644
--- a/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/slack/SlackhookCallback.java
+++ b/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/slack/SlackhookCallback.java
@@ -76,6 +76,7 @@ public class SlackhookCallback implements AlarmCallback {
post.setHeader(HttpHeaders.CONTENT_TYPE, HttpHeaderValues.APPLICATION_JSON.toString());
StringEntity entity;
+ CloseableHttpResponse httpResponse = null;
try {
JsonObject jsonObject = new JsonObject();
JsonArray jsonElements = new JsonArray();
@@ -88,7 +89,7 @@ public class SlackhookCallback implements AlarmCallback {
jsonObject.add("blocks", jsonElements);
entity = new StringEntity(GSON.toJson(jsonObject), ContentType.APPLICATION_JSON);
post.setEntity(entity);
- CloseableHttpResponse httpResponse = httpClient.execute(post);
+ httpResponse = httpClient.execute(post);
StatusLine statusLine = httpResponse.getStatusLine();
if (statusLine != null && statusLine.getStatusCode() != HttpStatus.SC_OK) {
log.error("Send slack alarm to {} failure. Response code: {}", url , statusLine.getStatusCode());
@@ -97,6 +98,15 @@ public class SlackhookCallback implements AlarmCallback {
log.error("Alarm to JSON error, {} ", e.getMessage(), e);
} catch (IOException e) {
log.error("Send slack alarm to {} failure.", url , e);
+ } finally {
+ if (httpResponse != null) {
+ try {
+ httpResponse.close();
+ } catch (IOException e) {
+ log.error(e.getMessage(), e);
+ }
+
+ }
}
});
} finally {
diff --git a/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/wechat/WechatHookCallback.java b/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/wechat/WechatHookCallback.java
index 9ac1517..24bd8ad 100644
--- a/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/wechat/WechatHookCallback.java
+++ b/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/wechat/WechatHookCallback.java
@@ -82,6 +82,7 @@ public class WechatHookCallback implements AlarmCallback {
}
private void sendAlarmMessage(CloseableHttpClient httpClient, String url, String requestBody) {
+ CloseableHttpResponse httpResponse = null;
try {
HttpPost post = new HttpPost(url);
post.setConfig(requestConfig);
@@ -89,13 +90,22 @@ public class WechatHookCallback implements AlarmCallback {
post.setHeader(HttpHeaders.CONTENT_TYPE, HttpHeaderValues.APPLICATION_JSON.toString());
StringEntity entity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
post.setEntity(entity);
- CloseableHttpResponse httpResponse = httpClient.execute(post);
+ httpResponse = httpClient.execute(post);
StatusLine statusLine = httpResponse.getStatusLine();
if (statusLine != null && statusLine.getStatusCode() != HttpStatus.SC_OK) {
log.error("send wechat alarm to {} failure. Response code: {} ", url, statusLine.getStatusCode());
}
} catch (Throwable e) {
log.error("send wechat alarm to {} failure.", url, e);
+ } finally {
+ if (httpResponse != null) {
+ try {
+ httpResponse.close();
+ } catch (IOException e) {
+ log.error(e.getMessage(), e);
+ }
+
+ }
}
}
}